私は最近、SOAP を受け入れるように見える WCF Web サービス (LeadService.svc) を継承しました。これまでのところ、XML ファイルからサービスのメソッド TestLead() にデータをプッシュしようとしていますが、うまくいきません。
次のコードはサービス メソッドをトリガーしますが、サービス エンドで渡される値 (lead) は常に null です。それをテストするために、Visual Studio の 2 つのインスタンスを実行しています。1 つはサービスを実行し、もう 1 つは使用するテスト コードを実行しています。私はこれを少し噛んでいましたが、値をサービスメソッドに正常に渡す方法を理解できないようです。Fiddler で POST を構成しても、同じ結果が得られました (鉛の値は null)。このシナリオでは、サービス コード自体を変更することはできません。
以下の最初の部分 (クライアント コード) を除いて、すべてのコードはサービスからのものです。
どんなアドバイスでも大歓迎です。
クライアント
using (var client = new WebClient())
{
var data = File.ReadAllText(Server.MapPath("~/App_Data/data.xml"));
client.Headers.Add("Content-Type", "text/xml;charset=utf-8");
client.Headers.Add("SOAPAction", "\"http://tempuri.org/ILeadService/TestLead\"");
client.Encoding = Encoding.UTF8;
try
{
var response = client.UploadString("http://localhost:54881/LeadService.svc/", data);
Response.Write(response);
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
データ
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<TestLead xmlns="http://tempuri.org/">
<firstName>test</firstName>
</TestLead>
</soap:Body>
</soap:Envelope>
サービス
ServiceResponse TestLead(SimpleLead lead) // this is always null
{
// ...
return sr;
}
WSDL
<wsdl:definitions name="LeadService" targetNamespace="http://tempuri.org/">
<wsdl:types>
<xsd:schema targetNamespace="http://tempuri.org/Imports">
<xsd:import schemaLocation="http://localhost:54881/LeadService.svc?xsd=xsd2" namespace="http://tempuri.org/"/>
<xsd:import schemaLocation="http://localhost:54881/LeadService.svc?xsd=xsd0" namespace="http://schemas.microsoft.com/2003/10/Serialization/"/>
<xsd:import schemaLocation="http://localhost:54881/LeadService.svc?xsd=xsd1" namespace="http://schemas.datacontract.org/2004/07/123Services"/>
</xsd:schema>
</wsdl:types>
<wsdl:message name="ILeadService_TestLead_InputMessage">
<wsdl:part name="parameters" element="tns:TestLead"/>
</wsdl:message>
<wsdl:message name="ILeadService_TestLead_OutputMessage">
<wsdl:part name="parameters" element="tns:TestLeadResponse"/>
</wsdl:message>
<wsdl:portType name="ILeadService">
<wsdl:operation name="TestLead">
<wsdl:input wsaw:Action="http://tempuri.org/ILeadService/TestLead" message="tns:ILeadService_TestLead_InputMessage"/>
<wsdl:output wsaw:Action="http://tempuri.org/ILeadService/TestLeadResponse" message="tns:ILeadService_TestLead_OutputMessage"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="BasicHttpBinding_ILeadService" type="tns:ILeadService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="TestLead">
<soap:operation soapAction="http://tempuri.org/ILeadService/TestLead" 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="LeadService">
<wsdl:port name="BasicHttpBinding_ILeadService" binding="tns:BasicHttpBinding_ILeadService">
<soap:address location="http://localhost:54881/LeadService.svc"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
契約
namespace 123Services
{
[ServiceContract]
public interface ILeadService
{
[OperationContract]
ServiceResponse TestLead(SimpleLead lead);
}
[DataContract]
public class SimpleLead
{
[DataMember]
public string FirstName { get; set; }
}
}
Web.config
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<bindings>
<wsHttpBinding>
<binding name="123Services.LeadService">
<security mode="None">
<message clientCredentialType="UserName"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service name="123Services.LeadService" behaviorConfiguration="123Services.LeadServiceBehavior">
<endpoint address="" binding="basicHttpBinding" contract="123Services.ILeadService">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="123Services.LeadServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>