繁体   English   中英

服务客户端通信上的ContractFilter不匹配错误

[英]ContractFilter mismatch error on service client communication

编辑:我已经添加了对我尝试查找解决方案所做的代码的编辑,仍然错误是相同的。

下面整个文本的重点是:

WCF服务器无法与Objective-C客户端设置[OperationContract(ProtectionLevel = ProtectionLevel.None)][ServiceContract(Name = "IServer", Namespace = "http://tempuri.org/")][ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)]无法解决错误消息。 详细配置如下所示。

================================================== ================================所以我创建了一个服务并将其上传到服务器

web.config文件如下所示:

<?xml version="1.0"?>
 <configuration>
  <appSettings/>
  <connectionStrings/>
  <system.web>
   <compilation debug="true" targetFramework="4.0"/>
   <authentication mode="Windows"/>
   <customErrors mode="Off"></customErrors>
   <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
  </system.web>
  <system.webServer>
   <directoryBrowse enabled="true"/>
  </system.webServer>
  <system.serviceModel>
   <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="false" />
   <services>
     <service behaviorConfiguration="AppComService.Service1Behavior" name="AppComService.Service">
     <endpoint address="" binding="basicHttpBinding" contract="AppComService.ComService">
     </endpoint>
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
    </service>
   </services>
   <behaviors>
    <serviceBehaviors>
     <behavior name="AppComService.Service1Behavior">
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="false"/>
     </behavior>
    </serviceBehaviors>
   </behaviors>
  </system.serviceModel>
 </configuration>

这是服务代码:

[ServiceContract(Name = "IServer", Namespace = "http://tempuri.org/")]
public interface ComService
{
    [OperationContract(ProtectionLevel = ProtectionLevel.None)]
    string Foo();

    // TODO: Add your service operations here
}

...

[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)]
public class Service : ComService
{

    public string Foo() 
    {
        return "foo!";
    }
}

客户端是在Objective-c中完成的,配置如下:

NSString *soapMessage = [NSString stringWithFormat:
                         @"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
                         "<SOAP-ENV:Envelope \n"
                         "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" \n"
                         "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n"
                         "xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" \n"
                         "SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" \n"
                         "xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"> \n"
                         "<SOAP-ENV:Body> \n"
                         "<Login xmlns=\"http://tempuri.org/\"><username>username</username><password>password</password>"
                         "</Login> \n"
                         "</SOAP-ENV:Body> \n"
                         "</SOAP-ENV:Envelope>"];

NSURL *url = [NSURL URLWithString:@"http://api.tagastic.com/Service.svc/foo"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%i", (int)[soapMessage length]];
[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: @"http://tempuri.org/ComService/foo" forHTTPHeaderField:@"Soapaction"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

当我们尝试调用Foo()方法时,我们得到:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<s:Fault>
<faultcode xmlns:a="http://schemas.microsoft.com/ws/2005/05/addressing/none">
a:ActionNotSupported
</faultcode>
<faultstring xml:lang="hr-HR">
The message with Action 'http://tempuri.org/ComService/foo' 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).
</faultstring>
</s:Fault>
</s:Body>
</s:Envelope>

有谁知道如何解决这一问题?

我已经遍历了有关此问题的大多数主题,但是所有解决方案都无法解决我们的具体情况。

因此,最后我需要做一些事情:首先将网络调用添加到方法中:

[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "Foo")]

然后我将元素添加到web.config中:

<service behaviorConfiguration="AppComService.Service1Behavior" name="AppComService.Service">
   <endpoint address="../Service.svc"
      binding="webHttpBinding"
      contract="AppComService.ComService"
      behaviorConfiguration="webBehaviour" />
  </service>
...
  <endpointBehaviors>
    <behavior name="webBehaviour">
        <webHttp/>
    </behavior>
</endpointBehaviors>

就是这样。 客户端现在可以访问该服务。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM