错误:EndpointDispatcher上的ContractFilter不匹配

时间:2014-06-06 09:55:44

标签: iphone xcode web-services wcf soap

我正在开发一个使用WCF以json格式返回数据的iPhone应用程序。但是当我调用wcf服务时,我收到了错误:

<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="en-US">The message with Action 'IPhoneDevService/GetConferenceIdByEventUrlName' 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>

服务名称:IPhoneDevService.svc没有为此创建的接口。如果我使用接口,则会出现问题。

功能:

[ServiceContract(Namespace = "")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceBehaviorAttribute(IncludeExceptionDetailInFaults = true)]
    [DataContractFormat(Style = OperationFormatStyle.Document)]
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "IPhoneDevService" in code, svc and config file together.
    public class IPhoneDevService
    {

 [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest, RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Json)]
        [OperationContract]
        public string GetOneUserAuthentication(long confrenceid, string email, string password)
        {

            StringBuilder sbJson = new StringBuilder();


            try
            {
                User[] objuserdetails = new User[1];
                System.Nullable<short> strRet = 0;
                string strRetMsg = string.Empty;

                using (LINQTODBDataContext objDB = new LINQTODBDataContext())
                {
                    objuserdetails = objDB.s_t_UserLoginVerifyClient(email, password, ref strRet, ref strRetMsg).Select(res => new User
                    {
                        UserID = res.UserId,
                        Message = ExceptionMsg.GetMessage(Convert.ToInt32(strRet), strRetMsg)

                    }).ToArray();
                    if (strRet == 2)
                    {
                        new JavaScriptSerializer().Serialize(objuserdetails, sbJson);
                    }
                    else
                    {
                        new JavaScriptSerializer().Serialize(ExceptionMsg.GetMessage(Convert.ToInt32(strRet), strRetMsg), sbJson);
                    }

                }
            }

            catch (Exception ex)
            {
               return "";
            }

            return sbJson.ToString();
        }
}

xcode消费是:

NSString *soapMessage = [NSString stringWithFormat:@&quot;&lt;SOAP-ENV:Envelope xmlns:SOAP-ENV=\&quot;http://schemas.xmlsoap.org/soap/envelope/\ &lt;http://schemas.xmlsoap.org/soap/envelope/%5C&gt;&quot;&gt;&lt;SOAP-ENV:Body&gt;&lt;GetOneUserAuthentication&gt;&lt;confrenceid&gt;123&lt;/confrenceid&gt;&lt;email&gt;demo@abc.com &lt;mailto:demo@abc.com&gt;&lt;/email&gt;&lt;password&gt;abc&lt;/password&gt;&lt;/GetOneUserAuthentication&gt;&lt;/SOAP-ENV:Body&gt;&lt;/SOAP-ENV:Envelope&gt;&quot;];


NSURL *url = [NSURL URLWithString:@"http://mydomain.com/IPhoneDevService.svc/basic"];

NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@&amp;quot;%d&amp;quot;, [soapMessage length]];

[theRequest addValue: @&amp;quot;text/xml; charset=utf-8&amp;quot; forHTTPHeaderField:@&amp;quot;Content-Type&amp;quot;];
[theRequest addValue:@&amp;quot;IPhoneDevService/GetOneUserAuthentication&amp;quot; forHTTPHeaderField:@&amp;quot;SOAPAction&amp;quot;];
[theRequest addValue: msgLength forHTTPHeaderField:@&amp;quot;Content-Length&amp;quot;];
[theRequest setHTTPMethod:@&amp;quot;POST&amp;quot;];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];

NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

WCF webconfig的服务模型是:

<system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    <bindings>
      <basicHttpBinding>
        <binding name="bhbinding" allowCookies="false">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <security mode="None" />
        </binding>
      </basicHttpBinding>

    </bindings>
    <behaviors>
      <endpointBehaviors>
        <behavior name="web">
          <webHttp />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehaviour">
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true" />
          <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true" />
          <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false" />
          <serviceThrottling maxConcurrentCalls="400" maxConcurrentInstances="400" maxConcurrentSessions="400" />
        </behavior>
        <behavior name="IphoneServiceBehaviour">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
          <useRequestHeadersForMetadataAddress>
            <defaultPorts>
              <add scheme="http" port="8081" />
              <add scheme="https" port="444" />
            </defaultPorts>
          </useRequestHeadersForMetadataAddress>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service name="Configurator_Service.IPhoneDevService" behaviorConfiguration="IphoneServiceBehaviour">
        <endpoint address="basic" binding="basicHttpBinding" bindingConfiguration="bhbinding" contract="Configurator_Service.IPhoneDevService" />
      </service>
    </services>
  </system.serviceModel>

1 个答案:

答案 0 :(得分:0)

您似乎已将端点配置错误。

在您的WCF配置中,您有:

<endpoint address="basic"

但在您的XCode中指定

http://.../IPhoneDevService.svc

您在配置中指定的端点地址将如下所示:

http://.../IPhoneDevService.svc/basic

通常,您只需将端点地址留空,除非您需要多个端点地址(例如,如果您想要公开MEX端点)。