SOAP-body WCF Web服务

时间:2018-01-04 07:34:26

标签: c# wcf soap

我有WCF网络方法的以下课程

[ServiceContract]
public interface IWebHook
{ 
    [OperationContract]
    SystemHealthCheckResponse SystemHealthCheck(SystemHealthCheckRequest request);
}


public class WebHookService : IWebHook
{
    public SystemHealthCheckResponse SystemHealthCheck(SystemHealthCheckRequest request)
    {
            // TODO: Written some logic
    }
} 

以下是请求代码

[Serializable]
[DataContract]
public class BaseRequest
{
    [DataMember]
    public DateTime RequestDateTime { get; set; }
}

[Serializable]
[DataContract]
public class SystemHealthCheckRequest : BaseRequest
{ 
    [DataMember]
    public Double HealthInquiryId { get; set; }
}

[DataContract]
public class SystemHealthCheckResponse : BaseResponse
{
    [DataMember]
    public bool IsServiceAvailable { get; set; }
}

使用JAVA(通过HTTP)无效的客户端SOAP请求

 <?xml version="1.0" ?> 
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
    <S:Body>
        <request:SystemHealthCheck xmlns:request="http://www.consumertestservices.com/schema/request">
             <request:RequestDateTime>2018-01-02 15:46:00</request:RequestDateTime>
            <request:HealthInquiryId>11131514936760789597</request:HealthInquiryId>
        </request:SystemHealthCheck>
    </S:Body>
</S:Envelope>

使用POSTMAN工作的客户端SOAP请求

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">

  <s:Body>
    <SystemHealthCheck xmlns="http://tempuri.org/">
      <request xmlns:d4p1="http://schemas.datacontract.org/2004/07/Provider.Entities" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
        <d4p1:RequestDateTime>2018-01-02 15:46:00</d4p1:RequestDateTime>
        <d4p1:HealthInquiryId>11131514936760789597</d4p1:HealthInquiryId>
      </request>
    </SystemHealthCheck>
  </s:Body>
</s:Envelope>

现在我能看到的区别是

<SystemHealthCheck xmlns="http://tempuri.org/">方法名称为TAG

客户端<request:SystemHealthCheck xmlns:request="http://www.consumertestservices.com/schema/request">中的WHERE方法带有前缀

错误:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Body>
        <s:Fault>
            <faultcode xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher">a:InternalServiceFault</faultcode>
            <faultstring xml:lang="en-US">Error in deserializing body of request message for operation 'SystemHealthCheck'. OperationFormatter encountered an invalid Message body. Expected to find node type 'Element' with name 'SystemHealthCheck' and namespace 'http://tempuri.org/'. Found node type 'Element' with name 'request:SystemHealthCheck' and namespace 'http://www.pushnotify.services.i2c.com/schema/request'</faultstring>
            <detail>
                <ExceptionDetail xmlns="http://schemas.datacontract.org/2004/07/System.ServiceModel" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
                    <HelpLink i:nil="true"/>
                    <InnerException>
                        <HelpLink i:nil="true"/>
                        <InnerException i:nil="true"/>
                        <Message>OperationFormatter encountered an invalid Message body. Expected to find node type 'Element' with name 'SystemHealthCheck' and namespace 'http://tempuri.org/'. Found node type 'Element' with name 'request:SystemHealthCheck' and namespace 'http://www.consumertestservices.com/schema/request'</Message>
                        <StackTrace>   at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeBody(XmlDictionaryReader reader, MessageVersion version, String action, MessageDescription messageDescription, Object[] parameters, Boolean isRequest)&#xD;
   at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeBodyContents(Message message, Object[] parameters, Boolean isRequest)&#xD;
   at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeRequest(Message message, Object[] parameters)</StackTrace>
                        <Type>System.Runtime.Serialization.SerializationException</Type>
                    </InnerException>
                    <Message>Error in deserializing body of request message for operation 'SystemHealthCheck'. OperationFormatter encountered an invalid Message body. Expected to find node type 'Element' with name 'SystemHealthCheck' and namespace 'http://tempuri.org/'. Found node type 'Element' with name 'request:SystemHealthCheck' and namespace 'http://www.consumertestservices.com/schema/request'</Message>
                    <StackTrace>   at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeRequest(Message message, Object[] parameters)&#xD;
   at System.ServiceModel.Dispatcher.DispatchOperationRuntime.DeserializeInputs(MessageRpc&amp; rpc)&#xD;
   at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&amp; rpc)&#xD;
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&amp; rpc)&#xD;
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc&amp; rpc)&#xD;
   at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)</StackTrace>
                    <Type>System.ServiceModel.CommunicationException</Type>
                </ExceptionDetail>
            </detail>
        </s:Fault>
    </s:Body>
</s:Envelope>

0 个答案:

没有答案