简体   繁体   中英

ContractFilter mismatch error on service client communication

EDIT: I have added edits to the code that i made to try and find a solution, still the error is the same.

The point of the whole block of text below is:

The WCF server cannot talk with the Objective-C client Setting [OperationContract(ProtectionLevel = ProtectionLevel.None)] , [ServiceContract(Name = "IServer", Namespace = "http://tempuri.org/")] and [ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)] didn't resolve the error message. Detailed configuration is shown below.

================================================================================== So i created a service and uploaded it to a server

the web.config file goes as follows:

<?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>

And here is the service code:

[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!";
    }
}

The client is done in Objective-c, and the configuration goes as follows:

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];

when we try to call the Foo() method we get:

<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>

Does anyone know how to fix this?

I have already run through most of the topics regarding this matter, but all of the solutions failed to to solve our specific situation.

So in the end i needed to do a few things: first added the web invoke to the metoods:

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

then i added elements to the 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>

and that was it. the client can now access the service.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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