Soap获得了额外的子级元素。
<Soapevn:Body>
<ImgSrch> --Name of the operation. It takes ImgSrch_MType as parameter
<ImgSrch_MType> -- why is this showing?. It is not a child element ImgSrch. ImgSrch is of type ImgSrch_Mtype
<DocImgIdxArray>
</DocImgIdxArray>
</ImgSrch_MType>
</ImgSrch>
</soapenv:Body>
必须是
<Soapevn:Body>
<ImgSrch> --name of the operation. It takes ImgSrch_MType as parameter
<SrchMsgRqHdr>
</SrchMsgRqHdr>
<DocImgIdxArray>
</DocImgIdxArray>
</ImgSrch>
</soapenv:Body>
这是wsdl。
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:tns="http://jackhenry.com/jxchange/TPG/2008" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" name="Image" targetNamespace="http://jackhenry.com/jxchange/TPG/2008">
<wsdl:types>
<xsd:schema targetNamespace="http://company.com">
<xsd:import schemaLocation="http://localhost/ImgSrch.svc?xsd=xsd0" namespace="http://somecompany.com"/>
</xsd:schema>
</wsdl:types>
<wsdl:message name="IImgService_ImgSrch_InputMessage">
<wsdl:part name="parameters" element="tns:ImgSrch"/>
</wsdl:message>
<wsdl:message name="IImgService_ImgSrch_OutputMessage">
<wsdl:part name="parameters" element="tns:ImgSrchResponse"/>
</wsdl:message>
<wsdl:portType name="IImgService">
<wsdl:operation name="ImgSrch">
<wsdl:input wsaw:Action="http://company.com/ws/ImgSrch" message="tns:IImgService_ImgSrch_InputMessage"/>
<wsdl:output wsaw:Action="http://company.com/ws/ImgSrchResponse" message="tns:IImgService_ImgSrch_OutputMessage"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="BasicHttpEndPoint" type="tns:IImgService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="ImgSrch">
<soap:operation soapAction="http://company.com/ws/ImgSrch" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="Image">
<wsdl:port name="BasicHttpEndPoint" binding="tns:BasicHttpEndPoint">
<soap:address location="http://localhost/ImgSrch.svc"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
<xsd:element name="ImgSrch" type="ImgSrch_MType" />
<xsd:complexType name="ImgSrch_MType">
<xsd:sequence>
<xsd:element name="MsgRqHdr" type="MsgRqHdr_CType" />
<xsd:element name="ImgIdxArray" type="ImgIdxArray_AType" />
<xsd:element minOccurs="0" name="IdxOnly" nillable="true" type="IdxOnly_Type" />
<xsd:element minOccurs="0" name="Custom" nillable="true" type="Custom_CType" />
<xsd:sequence minOccurs="0">
<xsd:element name="Ver_1" type="Ver_1_CType" />
<xsd:element minOccurs="0" name="DocImgFilterType" nillable="true" type="DocImgFilterType_Type" />
<xsd:sequence minOccurs="0">
<xsd:element name="Ver_2" type="Ver_2_CType" />
<xsd:element minOccurs="0" name="DocImgFormat" type="DocImgFormat_Type" />
<xsd:sequence minOccurs="0">
<xsd:element name="Ver_3" type="Ver_3_CType" />
<xsd:any minOccurs="0" maxOccurs="unbounded" namespace="##targetNamespace" processContents="lax" />
</xsd:sequence>
</xsd:sequence>
</xsd:sequence>
</xsd:sequence>
</xsd:complexType>
public partial class ImgSrch_MType
{
[DataMember]
public DocImgIdx_CType[] DocImgIdxArray
}`enter code here`
ImgSrch_MType具有一些元素,但是以某种方式显示为操作名称之后的第二到顶层。有人可以建议吗?该操作采用ImgSrch接受类型为ImgSrch_MType的参数。
答案 0 :(得分:1)
您可以尝试MessageContract,它可以指定序列化的xml。
但是您应该注意,返回的类型还应该具有MessageContract属性。
下面是我的测试代码。
[MessageContract(WrapperName ="ImgSrch")]// specify the root element
public class Customer
{
[MessageBodyMember(Name ="DocImgIdxArray")] // specify the first child element
public string FirstName { get; set; }
}
[ServiceContract]
public interface ICustomerService
{
[OperationContract]
Customer GetCustomer(Customer customer);
}
public class CustomerService : ICustomerService
{
public Customer GetCustomer(Customer customer)
{
return customer;
}
}