简体   繁体   English

为什么我的WCF客户端/服务会收到ActionNotSupportedException?

[英]Why do I get ActionNotSupportedException for my WCF client/service?

I'm learning WCF, specifically I'm learning how to write them contract first, ala wscf.blue 我正在学习WCF,特别是我正在学习如何将它们写成合同,ala wscf.blue

I can create a WCF client/service the contract last way (Microsoft) I can create a WCF client/service the contract first way (WSCF) 我可以创建一个WCF客户端/服务合同的最后一种方式(微软)我可以创建一个WCF客户端/服务合同的第一种方式(WSCF)

But, if I create a contract first service, then try to add it the Microsoft way (Service Reference) instead of the WSCF.blue way (share contract and generate client) it doesn't work. 但是,如果我创建合同第一个服务,然后尝试添加Microsoft方式(服务参考)而不是WSCF.blue方式(共享合同和生成客户端)它不起作用。

It throws an ActionNotSupportedException with the 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, eg Message, Transport, None). 它抛出一个ActionNotSupportedException ,消息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, eg Message, Transport, None). 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, eg Message, Transport, None).

And I have no idea what that means. 我不知道这意味着什么。

Here is my test contract: 这是我的测试合同:

SimpleModel.xsd SimpleModel.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 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>

Simple.wsdl Simple.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>

Here's the system.serviceModel section from web.config 这是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>

If I add a service reference to http://localhost:50862/Simple.svc Every appears to generate OK. 如果我向http://localhost:50862/Simple.svc添加服务引用, http://localhost:50862/Simple.svc每个似乎都生成OK。

I create this in the client app.config using the service config editor by importing the web.config: 我通过导入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>

And if I run my test code: 如果我运行我的测试代码:

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();
}

Inside the TestMethod proxy the following line: 在TestMethod代理中,以下行:

return base.Channel.TestMethod(request);

Throws the following exception 引发以下异常

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)

Can anybody help? 有人可以帮忙吗?

Thanks, 谢谢,

J. J.

First Edit 首先编辑

OK, I've now found that there is something going wrong with my doc-lit-wrapped wsdl and the code generators. 好的,我现在发现我的doc-lit-wrapped wsdl和代码生成器出了问题。 wscf.blue does not like it's messages to have nullable types marked as nillable. wscf.blue不喜欢它的消息,可以将nullable类型标记为nillable。 It falls out of wrapped mode and the method implementations are not unwrapped. 它不属于包装模式,方法实现也没有解开。

But, if I don't mark them as nillable, the client code falls out of wrapping mode because they are nullable types not marked as nillable. 但是,如果我没有将它们标记为nillable,则客户端代码将脱离包装模式,因为它们是可空类型,未标记为可为空。

With nullable types marked not nillable: 可空类型标记为无法填充:

Server side: 服务器端:

[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);

Client Side: 客户端:

// 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);

With nullable types marked as nillable: 可空类型标记为可为空:

Server side: 服务器端:

// 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);

Client side: 客户端:

[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);

However I have no idea whether that's the cause, let alone how to fix it. 但是我不知道这是否是原因,更不用说如何解决它。 That said, I do know that nullable types should be marked nillable for doc-lit-wrapped wsdl. 这就是说,我知道 ,可空类型,应标示为的nillable DOC点亮的包装的WSDL。

I think the problem is contract. 我认为问题是合同。 In client generated, you can see contract="SI.SimpleInterface", but in service definition contract="ISimple". 在客户端生成中,您可以看到contract =“SI.SimpleInterface”,但在服务定义合约=“ISimple”中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我的WCF客户端无法连接到我的WCF服务? - Why can't my WCF Client connect to my WCF Service? 即使我的服务调用和回调成功,为什么我仍收到WCF超时? - Why do I get a WCF timeout even though my service call and callback are successful? 如何从WCF服务应用程序获取客户端的地址? - How do I get a client's address from a WCF Service Application? 为什么必须在WPF中创建对WCF的服务引用? - Why do I have to create a Service Reference to the WCF within my WPF? 当客户端甚至无法连接到WCF服务器时,为什么会出现“服务器堆栈跟踪”的异常? - Why do I get an exception with “server stack trace” when the client can't even connect to WCF server? C# WCF 服务获取客户服务 - C# WCF service get client service 我在哪里可以得到WCF服务来处理X509证书? C#.NET - Where do I get my WCF service to handle X509 certificates? C#.NET 为什么在尝试连接到本地主机上的WCF服务时WCF客户端有时会超时? - Why is my WCF client timing out sometimes when trying to connect to the WCF Service on localhost? 为什么我的wcf服务请求标题总是得到 - Why my wcf service request headers always get 为什么我的C#客户端,POST到我的WCF REST服务,返回(400)错误请求? - Why does my C# client, POSTing to my WCF REST service, return (400) Bad Request?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM