我正在学习 WCF,特别是我正在学习如何先编写契约(Contract),ala wscf.blue
我可以用最后一种方式创建 WCF 客户端/服务契约(Contract) (Microsoft) 我可以通过契约(Contract)优先方式 (WSCF) 创建 WCF 客户端/服务
但是,如果我首先创建契约(Contract)服务,然后尝试以 Microsoft 方式(服务引用)而不是 WSCF.blue 方式(共享契约(Contract)并生成客户端)添加它,则它不起作用。
它抛出一个 ActionNotSupportedException 消息 The message with Action 'urn:test-com:simple:testMethodIn' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher .这可能是因为契约(Contract)不匹配(发送方和接收方之间的操作不匹配)或发送方和接收方之间的绑定(bind)/安全不匹配。检查发送方和接收方是否具有相同的契约(Contract)和相同的绑定(bind)(包括安全要求,例如消息、传输、无)。
我不知道那是什么意思。
这是我的测试合约:
简单模型.xsd
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns="urn:test-com:simple" xmlns:mstns="urn:test-com:simple" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:test-com:simple" elementFormDefault="qualified" attributeFormDefault="unqualified" id="SimpleModel">
<xs:complexType name="PayloadType">
<xs:sequence>
<xs:element name="AString" type="xs:string" nillable="1" minOccurs="0"/>
<xs:element name="AnInt" type="xs:int"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
SimpleMessages.xsd
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns="urn:test-com:simple" xmlns:mstns="urn:test-com:simple" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:smod="http://tempuri.org/SimpleModel.xsd" targetNamespace="urn:test-com:simple" elementFormDefault="qualified" attributeFormDefault="unqualified" id="SimpleMessages">
<xs:include schemaLocation="SimpleModel.xsd"/>
<xs:element name="TestMethod">
<xs:complexType>
<xs:sequence>
<xs:element name="APayload" type="PayloadType" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="TestMethodResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="Output" type="PayloadType"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
简单的.wsdl
<!--WSDL generated by thinktecture WSCF; version 1.0.13.0-->
<!--Tuesday, 09-10-2012 - 02:41 PM-->
<definitions xmlns:tns="urn:test-com:simple" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" name="Simple" targetNamespace="urn:test-com:simple">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"/>
<types>
<xsd:schema>
<xsd:import schemaLocation="SimpleMessages.xsd" namespace="urn:test-com:simple"/>
</xsd:schema>
</types>
<message name="testMethodIn">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"/>
<part name="parameters" element="tns:TestMethod"/>
</message>
<message name="testMethodOut">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"/>
<part name="parameters" element="tns:TestMethodResponse"/>
</message>
<portType name="SimpleInterface">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"/>
<operation name="TestMethod">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"/>
<input message="tns:testMethodIn"/>
<output message="tns:testMethodOut"/>
</operation>
</portType>
<binding name="BasicHttpBinding_SimpleInterface" type="tns:SimpleInterface">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="TestMethod">
<soap:operation soapAction="urn:test-com:simple:testMethodIn" style="document"/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="ISimple">
<port name="NewPort" binding="tns:BasicHttpBinding_SimpleInterface">
<soap:address location="http://localhost:50862/Simple.svc"/>
</port>
</service>
</definitions>
这是来自 web.config 的 system.serviceModel 部分
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="SimpleServiceBehaviour">
<serviceMetadata externalMetadataLocation="http://localhost:50862/TestContract/Simple.wsdl" httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<diagnostics>
<messageLogging logMalformedMessages="true" logMessagesAtTransportLevel="true"/>
</diagnostics>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_SimpleInterface" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
<message clientCredentialType="UserName" algorithmSuite="Default"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="SimpleServiceBehaviour" name="SimpleContract.Simple">
<endpoint address="http://localhost:50862/Simple.svc" behaviorConfiguration="" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_SimpleInterface" contract="ISimple"/>
</service>
</services>
</system.serviceModel>
如果我添加对 http://localhost:50862/Simple.svc 的服务引用,Every 似乎生成 OK。
我通过导入 web.config 使用服务配置编辑器在客户端 app.config 中创建它:
<system.serviceModel>
<client>
<endpoint address="http://localhost:50862/Simple.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_SimpleInterface" contract="SI.SimpleInterface" name="NewPort"/>
</client>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_SimpleInterface" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
<message clientCredentialType="UserName" algorithmSuite="Default"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
</system.serviceModel>
如果我运行我的测试代码:
static void Main(string[] args)
{
SimpleInterfaceClient client = new SimpleInterfaceClient();
var ret = client.TestMethod(new PayloadType() { AnInt = 7, AString = "bob" });
Console.WriteLine(ret.ToString());
Console.ReadLine();
}
在 TestMethod 代理内部,以下行:
return base.Channel.TestMethod(request);
抛出以下异常
System.ServiceModel.ActionNotSupportedException occurred
Message="The message with Action 'urn:test-com:simple:testMethodIn' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None)."
Source="System.ServiceModel"
StackTrace:
at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)
有人可以帮忙吗?
谢谢,
J.
第一次编辑
好的,我现在发现我的 doc-lit-wrapped wsdl 和代码生成器出了点问题。 wscf.blue 不喜欢将可空类型标记为可空的消息。它脱离了包装模式,并且方法实现没有展开。
但是,如果我不将它们标记为可为 nillable,则客户端代码将退出包装模式,因为它们是未标记为 nillable 的可为 null 类型。
可空类型标记为不可空:
服务器端:
[System.ServiceModel.OperationContractAttribute(Action="urn:test-com:simple/ISimple/TestMethod", ReplyAction="urn:test-com:simple/ISimple/TestMethodResponse")]
[System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults=true)]
[return: System.ServiceModel.MessageParameterAttribute(Name="Output")]
PayloadType TestMethod(PayloadType APayload);
客户端:
// CODEGEN: Generating message contract since element name APayload from namespace urn:test-com:simple is not marked nillable
[System.ServiceModel.OperationContractAttribute(Action="urn:test-com:simple:testMethodIn", ReplyAction="*")]
DesktopClientTest_ServiceReference.SI.TestMethodResponse TestMethod(DesktopClientTest_ServiceReference.SI.TestMethodRequest request);
将可空类型标记为可空:
服务器端:
// CODEGEN: Parameter 'Output' requires additional schema information that cannot be captured using the parameter mode. The specific attribute is 'System.Xml.Serialization.XmlElementAttribute'.
[System.ServiceModel.OperationContractAttribute(Action="urn:test-com:simple/ISimple/TestMethod", ReplyAction="urn:test-com:simple/ISimple/TestMethodResponse")]
[System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults=true)]
[return: System.ServiceModel.MessageParameterAttribute(Name="Output")]
TestMethodResponse TestMethod(TestMethodRequest request);
客户端:
[System.ServiceModel.OperationContractAttribute(Action="urn:test-com:simple:testMethodIn", ReplyAction="*")]
[return: System.ServiceModel.MessageParameterAttribute(Name="Output")]
DesktopClientTest_ServiceReference.SI.PayloadType TestMethod(DesktopClientTest_ServiceReference.SI.PayloadType APayload);
但是我不知道这是否是原因,更不用说如何解决了。 也就是说,我确实知道对于 doc-lit-wrapped wsdl,可以为 null 的类型应该标记为 nillable。
最佳答案
我认为问题出在契约(Contract)上。在生成的客户端中,您可以看到 contract="SI.SimpleInterface",但在服务定义 contract="ISimple"中。
关于c# - 为什么我的 WCF 客户端/服务会出现 ActionNotSupportedException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12819688/
类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc
我有一个模型:classItem项目有一个属性“商店”基于存储的值,我希望Item对象对特定方法具有不同的行为。Rails中是否有针对此的通用设计模式?如果方法中没有大的if-else语句,这是如何干净利落地完成的? 最佳答案 通常通过Single-TableInheritance. 关于ruby-on-rails-Rails-子类化模型的设计模式是什么?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.co
我正在使用的第三方API的文档状态:"[O]urAPIonlyacceptspaddedBase64encodedstrings."什么是“填充的Base64编码字符串”以及如何在Ruby中生成它们。下面的代码是我第一次尝试创建转换为Base64的JSON格式数据。xa=Base64.encode64(a.to_json) 最佳答案 他们说的padding其实就是Base64本身的一部分。它是末尾的“=”和“==”。Base64将3个字节的数据包编码为4个编码字符。所以如果你的输入数据有长度n和n%3=1=>"=="末尾用于填充n%
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
为什么4.1%2返回0.0999999999999996?但是4.2%2==0.2。 最佳答案 参见此处:WhatEveryProgrammerShouldKnowAboutFloating-PointArithmetic实数是无限的。计算机使用的位数有限(今天是32位、64位)。因此计算机进行的浮点运算不能代表所有的实数。0.1是这些数字之一。请注意,这不是与Ruby相关的问题,而是与所有编程语言相关的问题,因为它来自计算机表示实数的方式。 关于ruby-为什么4.1%2使用Ruby返
它不等于主线程的binding,这个toplevel作用域是什么?此作用域与主线程中的binding有何不同?>ruby-e'putsTOPLEVEL_BINDING===binding'false 最佳答案 事实是,TOPLEVEL_BINDING始终引用Binding的预定义全局实例,而Kernel#binding创建的新实例>Binding每次封装当前执行上下文。在顶层,它们都包含相同的绑定(bind),但它们不是同一个对象,您无法使用==或===测试它们的绑定(bind)相等性。putsTOPLEVEL_BINDINGput
我可以得到Infinity和NaNn=9.0/0#=>Infinityn.class#=>Floatm=0/0.0#=>NaNm.class#=>Float但是当我想直接访问Infinity或NaN时:Infinity#=>uninitializedconstantInfinity(NameError)NaN#=>uninitializedconstantNaN(NameError)什么是Infinity和NaN?它们是对象、关键字还是其他东西? 最佳答案 您看到打印为Infinity和NaN的只是Float类的两个特殊实例的字符串
如果您尝试在Ruby中的nil对象上调用方法,则会出现NoMethodError异常并显示消息:"undefinedmethod‘...’fornil:NilClass"然而,有一个tryRails中的方法,如果它被发送到一个nil对象,它只返回nil:require'rubygems'require'active_support/all'nil.try(:nonexisting_method)#noNoMethodErrorexceptionanymore那么try如何在内部工作以防止该异常? 最佳答案 像Ruby中的所有其他对象
关闭。这个问题需要detailsorclarity.它目前不接受答案。想改进这个问题吗?通过editingthispost添加细节并澄清问题.关闭8年前。Improvethisquestion为什么SecureRandom.uuid创建一个唯一的字符串?SecureRandom.uuid#=>"35cb4e30-54e1-49f9-b5ce-4134799eb2c0"SecureRandom.uuid方法创建的字符串从不重复?
我是一个Rails初学者,但我想从我的RailsView(html.haml文件)中查看Ruby变量的内容。我试图在ruby中打印出变量(认为它会在终端中出现),但没有得到任何结果。有什么建议吗?我知道Rails调试器,但更喜欢使用inspect来打印我的变量。 最佳答案 您可以在View中使用puts方法将信息输出到服务器控制台。您应该能够在View中的任何位置使用Haml执行以下操作:-puts@my_variable.inspect 关于ruby-on-rails-如何在我的R