C# C SOAP服务-删除方法节点并在soapheader节点中具有标头
我的任务是创建一个符合特定wsdl的web服务,我以前没有使用过SOAP或asmx 当我在SoapUI中创建请求时,我得到了以下结构,它与客户端将用于发送请求的结构相同。使用占位符名称C# C SOAP服务-删除方法节点并在soapheader节点中具有标头,c#,soap,asmx,C#,Soap,Asmx,我的任务是创建一个符合特定wsdl的web服务,我以前没有使用过SOAP或asmx 当我在SoapUI中创建请求时,我得到了以下结构,它与客户端将用于发送请求的结构相同。使用占位符名称 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:par="http://www.foo.com/schemas/method"> <soapenv:Header>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:par="http://www.foo.com/schemas/method">
<soapenv:Header>
<par:SOAPHeaderRequest>
<par:ApplicationID>ID</par:ApplicationID>
</par:SOAPHeaderRequest>
</soapenv:Header>
<soapenv:Body>
<par:Body>
</par:Body>
</soapenv:Body>
</soapenv:Envelope>
asmx
如果您还需要什么,请告诉我
谢谢 WSDL区分了两种消息样式: 文档和RPC 消息样式影响SOAP正文的内容: 文档样式:SOAP主体包含一个或多个子元素,称为parts。对于主体包含的内容,没有SOAP格式规则;它包含发送方和接收方同意的任何内容 **RPC样式:**RPC表示SOAP主体包含一个元素,该元素的名称为所调用的方法或操作的名称。该元素依次包含该方法/操作的每个参数的元素 您的wsdl是以文档文字样式编写的 如果您使用的是服务契约,那么我相信您使用的是WCF框架来编写服务代码 您可以指定以下参数,以按预期生成WSDL
[ServiceContract(Namespace="http://Microsoft.ServiceModel.Samples"), XmlSerializerFormat(Style = OperationFormatStyle.Document,
Use = OperationFormatUse.Literal)]
参考-
希望这有帮助。非常感谢!
[ServiceContract(Namespace = "http://www.foo.com/schemas/method")]
public interface IServiceContract
{
[XmlSerializerFormat]
[OperationContract]
ResponseObject Method(RequestObject request);
}
[System.Serializable()]
[System.Xml.Serialization.XmlType(AnonymousType = true, Namespace = "http://www.foo.com/schemas/method")]
[MessageContract(IsWrapped = false)]
public class RequestObject
{
[System.ServiceModel.MessageHeader(Namespace = "http://www.foo.com/schemas/method")]
public SOAPHeaderRequest SOAPHeaderRequest;
[System.ServiceModel.MessageBodyMember(Namespace = "http://www.foo.com/schemas/method", Order = 0)]
public Body body;
public RequestObject()
{
}
public RequestObject(SOAPHeaderRequest SOAPHeaderRequest, Body body)
{
this.body = body;
}
}
[System.Serializable()]
[System.Xml.Serialization.XmlType(AnonymousType = true, Namespace = "http://www.foo.com/schemas/method")]
[MessageContract(IsWrapped = false)]
public class ResponseObject
{
[System.ServiceModel.MessageHeader(Namespace = "http://www.foo.com/schemas/method")]
public SOAPHeaderResponse SOAPHeaderResponse;
[System.ServiceModel.MessageBodyMember(Namespace = "http://www.foo.com/schemas/method", Order = 0)]
public Body body;
}
[System.Serializable()]
public class Body
{
public string Property { get; set; }
}
[WebService(Namespace = "http://www.foo.com/schemas/method")]
[WebServiceBinding(ConformsTo = WsiProfiles.None)]
public class M5NapaPartUpdateService : WebService, IServiceContract
{
[WebMethod]
[SoapMethod(SoapAction = "method")]
public ResponseObject Method(RequestObject request)
{
return new ResponseObject();
}
}
[ServiceContract(Namespace="http://Microsoft.ServiceModel.Samples"), XmlSerializerFormat(Style = OperationFormatStyle.Document,
Use = OperationFormatUse.Literal)]