2017-10-26 15 views
0

wcf契約をから変更する方法はありますか?WCF契約の生成

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:biz="http://BizTalk.Test001.Customer"> 
<soapenv:Header/> 
<soapenv:Body> 
    <biz:Data> 
    <ID>?</ID> 
    <FirstName>?</FirstName> 
    <LastName>?</LastName> 
    <MobilePhone>?</MobilePhone> 
    <HomePhone>?</HomePhone> 
    <Email>?</Email> 
    <AddressLine1>?</AddressLine1> 
    <AddressLine2>?</AddressLine2> 
    <Suburb>?</Suburb> 
    <City>?</City> 
    <State>?</State> 
    <Country>?</Country> 
    </biz:Data> 

この

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://schemas.datacontract.org/2004/07/"> 
<soapenv:Header/> 
<soapenv:Body> 
    **<AddCustomer>** 
    <!--Optional:--> 
    <Data> 
     <ns:AddressLine1>?</ns:AddressLine1> 
     <ns:AddressLine2>?</ns:AddressLine2> 
     <ns:City>?</ns:City> 
     <ns:Country>?</ns:Country> 
     <ns:Email>?</ns:Email> 
     <ns:FirstName>?</ns:FirstName> 
     <ns:HomePhone>?</ns:HomePhone> 
     <ns:ID>?</ns:ID> 
     <ns:LastName>?</ns:LastName> 
     <ns:MobilePhone>?</ns:MobilePhone> 
     <ns:State>?</ns:State> 
     <ns:Suburb>?</ns:Suburb> 
    </Data> 
    **</AddCustomer>** 

基本的に私は、リクエストから "AddCustomer" を取り除きたいです。 ServiceContractまたはOperationContractを使用して何かを行うことはできますか?

答えて

0

あなたが要求を送信する前にIClientMessageInspector interface.Soを実装するために持っているか、応答をreceving後あなたは、詳細実装のチェックのために

public class ClientMessageInspector : IClientMessageInspector 
    { 
     public string LastRequestXml { get; private set; } 
     public string LastResponseXml { get; private set; } 
     public void AfterReceiveReply(ref Message reply, object correlationState) 
     { 
      LastResponseXml = reply.ToString(); 
     } 

     public object BeforeSendRequest(ref Message request, System.ServiceModel.IClientChannel channel) 
     { 
      LastRequestXml = request.ToString(); 
      var xmlPayload = ChangeMessage(); 
      var ms = new MemoryStream(); 
      var writer = new StreamWriter(ms); 
      writer.Write(xmlPayload); 
      writer.Flush(); 
      ms.Position = 0; 

      var reader = XmlReader.Create(ms); 
      request = Message.CreateMessage(reader, int.MaxValue, request.Version); 
      var payload = request.ToString(); 
      return request; 
     } 

     /// Manipulate the SOAP message 
     private string ChangeMessage() 
    { 
       //manipulation code here to remove AddCustomer. 
    } 
} 

、などのリクエスト/レスポンスSOAPメッセージを上書きするために、独自のC#のメソッドを実装する必要がありますこのブログ。 https://cmatskas.com/changing-soap-message-data-and-namespaces-with-c/

関連する問題