我需要为客户端创建一个使用/使用的服务(我认为消费是正确的术语)。
我是WCF
和web services
的新手。
我完成了大部分教程,并了解了一切是如何运作的。
现在我有了这个wsdl文件:
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:tns="http://196.37.139.18/IntegrationTest/ShopriteIntegrationService"
xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
targetNamespace="http://196.37.139.18/IntegrationTest/ShopriteIntegrationService">
<wsdl:types>
<s:schema elementFormDefault="qualified"
targetNamespace="http://196.37.139.18/IntegrationTest/ShopriteIntegrationService">
<s:element name="ChangePassword">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="serviceProviderGuid" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="oldPassword" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="newPassword" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="ChangePasswordResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="ChangePasswordResult">
<s:complexType mixed="true">
<s:sequence>
<s:any/>
</s:sequence>
</s:complexType>
</s:element>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="GetCampaignSchedulePlacements">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="serviceProviderGuid" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="password" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="GetCampaignSchedulePlacementsResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="GetCampaignSchedulePlacementsResult">
<s:complexType mixed="true">
<s:sequence>
<s:any/>
</s:sequence>
</s:complexType>
</s:element>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="ConfirmDownload">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="serviceProviderGuid" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="password" type="s:string"/>
<s:element minOccurs="1" maxOccurs="1" name="dateOfLatestRecordRecieved" type="s:dateTime"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="ConfirmDownloadResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="ConfirmDownloadResult">
<s:complexType mixed="true">
<s:sequence>
<s:any/>
</s:sequence>
</s:complexType>
</s:element>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="UploadCampaignSchedulePlacements">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="serviceProviderGuid" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="password" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="xml" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="UploadCampaignSchedulePlacementsResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="UploadCampaignSchedulePlacementsResult">
<s:complexType mixed="true">
<s:sequence>
<s:any/>
</s:sequence>
</s:complexType>
</s:element>
</s:sequence>
</s:complexType>
</s:element>
</s:schema>
</wsdl:types>
<wsdl:message name="ChangePasswordSoapIn">
<wsdl:part name="parameters" element="tns:ChangePassword"/>
</wsdl:message>
<wsdl:message name="ChangePasswordSoapOut">
<wsdl:part name="parameters" element="tns:ChangePasswordResponse"/>
</wsdl:message>
<wsdl:message name="GetCampaignSchedulePlacementsSoapIn">
<wsdl:part name="parameters" element="tns:GetCampaignSchedulePlacements"/>
</wsdl:message>
<wsdl:message name="GetCampaignSchedulePlacementsSoapOut">
<wsdl:part name="parameters" element="tns:GetCampaignSchedulePlacementsResponse"/>
</wsdl:message>
<wsdl:message name="ConfirmDownloadSoapIn">
<wsdl:part name="parameters" element="tns:ConfirmDownload"/>
</wsdl:message>
<wsdl:message name="ConfirmDownloadSoapOut">
<wsdl:part name="parameters" element="tns:ConfirmDownloadResponse"/>
</wsdl:message>
<wsdl:message name="UploadCampaignSchedulePlacementsSoapIn">
<wsdl:part name="parameters" element="tns:UploadCampaignSchedulePlacements"/>
</wsdl:message>
<wsdl:message name="UploadCampaignSchedulePlacementsSoapOut">
<wsdl:part name="parameters" element="tns:UploadCampaignSchedulePlacementsResponse"/>
</wsdl:message>
<wsdl:portType name="ShopriteIntegrationTestoap">
<wsdl:operation name="ChangePassword">
<wsdl:input message="tns:ChangePasswordSoapIn"/>
<wsdl:output message="tns:ChangePasswordSoapOut"/>
</wsdl:operation>
<wsdl:operation name="GetCampaignSchedulePlacements">
<wsdl:input message="tns:GetCampaignSchedulePlacementsSoapIn"/>
<wsdl:output message="tns:GetCampaignSchedulePlacementsSoapOut"/>
</wsdl:operation>
<wsdl:operation name="ConfirmDownload">
<wsdl:input message="tns:ConfirmDownloadSoapIn"/>
<wsdl:output message="tns:ConfirmDownloadSoapOut"/>
</wsdl:operation>
<wsdl:operation name="UploadCampaignSchedulePlacements">
<wsdl:input message="tns:UploadCampaignSchedulePlacementsSoapIn"/>
<wsdl:output message="tns:UploadCampaignSchedulePlacementsSoapOut"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="ShopriteIntegrationTestoap" type="tns:ShopriteIntegrationTestoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="ChangePassword">
<soap:operation soapAction="http://196.37.139.18/IntegrationTest/ShopriteIntegrationService/ChangePassword" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="GetCampaignSchedulePlacements">
<soap:operation soapAction="http://196.37.139.18/IntegrationTest/ShopriteIntegrationService/GetCampaignSchedulePlacements" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="ConfirmDownload">
<soap:operation soapAction="http://196.37.139.18/IntegrationTest/ShopriteIntegrationService/ConfirmDownload" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="UploadCampaignSchedulePlacements">
<soap:operation soapAction="http://196.37.139.18/IntegrationTest/ShopriteIntegrationService/UploadCampaignSchedulePlacements" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="ShopriteIntegrationServiceSoap12" type="tns:ShopriteIntegrationServiceSoap">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="ChangePassword">
<soap12:operation soapAction="http://196.37.139.18/IntegrationTest/ShopriteIntegrationService/ChangePassword" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="GetCampaignSchedulePlacements">
<soap12:operation soapAction="http://196.37.139.18/IntegrationTest/ShopriteIntegrationService/GetCampaignSchedulePlacements" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="ConfirmDownload">
<soap12:operation soapAction="http://196.37.139.18/IntegrationTest/ShopriteIntegrationService/ConfirmDownload" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="UploadCampaignSchedulePlacements">
<soap12:operation soapAction="http://196.37.139.18/IntegrationTest/ShopriteIntegrationService/UploadCampaignSchedulePlacements" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="ShopriteIntegrationService">
<wsdl:port name="ShopriteIntegrationServiceSoap" binding="tns:ShopriteIntegrationTestoap">
<soap:address location="http://jhbweb01/IntegrationTest/ShopriteIntegrationService.asmx"/>
</wsdl:port>
<wsdl:port name="ShopriteIntegrationServiceSoap12" binding="tns:ShopriteIntegrationServiceSoap12">
<soap12:address location="http://jhbweb01/IntegrationTest/ShopriteIntegrationService.asmx"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
这就是我得到的:
[ServiceContract]
public interface IShopriteService
{
[OperationContract]
void ChangePassword(string serviceProviderGuid, string oldPassword, DateTime newPassword);
[OperationContract]
string ChangePasswordResponse();
[OperationContract]
void GetCampaignSchedulePlacements(string serviceProviderGuid, string password);
[OperationContract]
string GetCampaignSchedulePlacementsResponse();
[OperationContract]
void ConfirmDownload(string serviceProviderGuid, string password, DateTime dateOfLatestRecordRecieved);
[OperationContract]
string ConfirmDownloadResponse();
[OperationContract]
void UploadCampaignSchedulePlacements(string serviceProviderGuid, string password, string xml);
[OperationContract]
string UploadCampaignSchedulePlacementsResponse();
}
实施方法:
public class ShopriteService : IShopriteService
{
public void ChangePassword(string serviceProviderGuid, string oldPassword, DateTime newPassword)
{
throw new NotImplementedException();
}
public string ChangePasswordResponse()
{
throw new NotImplementedException();
}
public void GetCampaignSchedulePlacements(string serviceProviderGuid, string password)
{
throw new NotImplementedException();
}
public string GetCampaignSchedulePlacementsResponse()
{
throw new NotImplementedException();
}
public void ConfirmDownload(string serviceProviderGuid, string password, DateTime dateOfLatestRecordRecieved)
{
throw new NotImplementedException();
}
public string ConfirmDownloadResponse()
{
throw new NotImplementedException();
}
public void UploadCampaignSchedulePlacements(string serviceProviderGuid, string password, string xml)
{
throw new NotImplementedException();
}
public string UploadCampaignSchedulePlacementsResponse()
{
throw new NotImplementedException();
}
}
我不知道我是否走在正确的轨道上......
解释一下wsdl
文件中发生了什么。
我从哪里开始?
我可以使用某种结构吗? (如MVVM
结构)
答案 0 :(得分:4)
请参阅有关如何创建WCF服务并将其与客户端应用程序一起使用的文章:
答案 1 :(得分:2)
WSDL只不过是对服务的描述,它允许客户端将其作为Web服务使用。 所以:wsdl反映了你的界面 - &gt;你的界面是由一个类实现的。最后一步是为您的接口方法编写逻辑(即:ChangePassword方法)。 另外,我得到的印象是ServiceContract有问题,让我们以ChangePassword方法为例: 因为该方法将返回一个字符串,您只需定义以下内容:
[OperationContract]
string ChangePassword(string serviceProviderGuid, string oldPassword, DateTime newPassword);
而不是
[OperationContract]
void ChangePassword(string serviceProviderGuid, string oldPassword, DateTime newPassword);
[OperationContract]
string ChangePasswordResponse();
所以基本上把你的WCF(或Ws)想象成一个传统的类库。它只允许通过HTTP/SOAP
进行调用和引用答案 2 :(得分:1)
我说你在路上!您可以使用任何您喜欢的设计模式来解决手头的问题。我通常将我的服务层设置得尽可能薄,只需通过某种界面抽象出底层逻辑,通常是Façade,这并不是说你的情况是正确的。
对于WSDL,它实际上是通过描述与服务公开的类型和端点相关的一组抽象来定义您的服务。您可以在W3C了解详情。通过WSDL,客户可以获取有关使用它所需服务的信息。
答案 3 :(得分:1)
您可以使用XML spy来了解映射到WCF服务和XSD的WSDL如何映射到数据协定 http://www.altova.com/simpledownload2c.html?gclid=CJeFgKGEr64CFSgntAod9m4oSA