2013-01-03 59 views
0

我有一个要求接受过在BizTalk HTTP HTTP MIME请求。如何通过WCF服务接受HTTP MIME请求通过HTTP在BizTalk

我创建使用WCF发布向导发布我的架构服务,并为SOAP + WSDL信封标准,但我怎么实现对HTTP/MIME多部分消息一样正常工作?

我试着在流水线的译码阶段,给出MIME解码器组件,但它抛出一个错误:

_415 Cannot process the message because the content type 'multipart/form-data; boundary=06047b04fd8d6d6866ed55ba' was not the expected type 'application/soap+xml; charset=utf-8'._ 

这里是我使用这我的样本MIME消息:

POST /core/Person HTTP/1.1 
Host: server_host:server_port 
Content-Length: 244508 
Content-Type: multipart/form-data; boundary=XbCY 
--XbCY 
Content-Disposition: form-data; name=“Name“ 
QWERTY 
--XbCY Content-Disposition: form-data; name=“Phno No" 
12234 
--XbCY 
Content-Disposition: form-data; name=“Address" 
00a0d91e6fa6 

我可以使用具有相同端点的相同服务?如果是这样,我需要在我的服务中做出什么样的改变?

我一定要使用任何自定义管道组件?

回答

0

你会希望有一个接收型HTTP的端口,并使用BTSHTTPReceive.dll,因为它看起来像没有SOAP信封。所以你基本上需要一个新的端点,而不是试图让WCF工作。

是的,你将不得不使用一个自定义管道组件。

此外,当您正在获取多部分/表单数据的MIME消息时,您需要阅读How to process “multipart/form-data” message submitted to BTSHttpReceive.dll,它将“MIME-Version:1.0”添加到消息中,以便您可以使用标准MIME解码器管道组件。

public IBaseMessage Execute(IPipelineContext pc, IBaseMessage inmsg) 
    { 
     IBaseMessagePart bodyPart = inmsg.BodyPart; 
     if (bodyPart!=null) 
     { 
      byte[] prependByteData = ConvertToBytes(prependData); 
      byte[] appendByteData = ConvertToBytes(appendData); 

      string headersString = inmsg.Context.Read("InboundHttpHeaders", "http://schemas.microsoft.com/BizTalk/2003/http-properties").ToString(); 
      string[] headers = headersString.Split(new Char[] {'\r','\n' }, StringSplitOptions.RemoveEmptyEntries); 
      string MimeHead=String.Empty; 
      bool Foundit=false; 
      for (int i=0;i<headers.Length;i++) 
      { 
       if (headers[i].StartsWith("Content-type:", true, null)) 
       { 
        MimeHead = headers[i]; 
        Foundit = true; 
        break; 
       } 
      } 
      if (Foundit) 
      { 
       StringBuilder sb = new StringBuilder(); 
       sb.Append(prependData); 
       sb.Append("\r\n"); 
       sb.Append(MimeHead); 
       sb.Append("\r\n"); 
       prependByteData = ConvertToBytes(sb.ToString()); 
      } 

       Stream originalStrm   = bodyPart.GetOriginalDataStream(); 
       Stream strm = null; 

       if (originalStrm != null) 
       { 
         strm    = new FixMsgStream(originalStrm, prependByteData, appendByteData, resManager); 
         bodyPart.Data = strm; 
         pc.ResourceTracker.AddResource(strm); 
       } 
     } 

     return inmsg; 
    } 

如果你想与你如何处理附件发烧友,看到这个博客Processing Binary Documents as XLANGMessages Through BizTalk Via Web Services

First I created a custom pipeline component to; Read the MIME encoded document using a BinaryReader into a byte array. Note you cannot use a StreamReader because the data in the stream is base64 encoded and will contain non-ASCII characters. Convert the byte array to a Base64 encoded string Create the typed XML document and add the base64 encode string to one of the elements. Send the XML document back out. The pipeline component code was;

public Microsoft.BizTalk.Message.Interop.IBaseMessage Execute(Microsoft.BizTalk.Component.Interop.IPipelineContext pc, Microsoft.BizTalk.Message.Interop.IBaseMessage inmsg) 
    { 
     var callToken = TraceManager.PipelineComponent.TraceIn(“START PIPELINE PROCESSING”); 
     //Assumes inmsg.BodyPart.Data is MIME encoded = base64 encoded   
     BinaryReader binReader = new BinaryReader(inmsg.BodyPart.Data); 
     byte[] dataOutAsBytes = binReader.ReadBytes((int)inmsg.BodyPart.Data.Length); 
     binReader.Close(); 
     string dataOut = System.Convert.ToBase64String(dataOutAsBytes); 
     TraceManager.PipelineComponent.TraceInfo(“Original MIME part received = ” + dataOut,callToken); 
     // THIS IS THE AttachedDoc XML MESSAGE THAT WE ARE CREATING 
     //<ns0:AttachedDocument xmlns:ns0=http://BT.Schemas.Internal/AttachedDocument> 
     // <ns0:FileName>FileName_0</ns0:FileName> 
     // <ns0:FilePath>FilePath_0</ns0:FilePath> 
     // <ns0:DocumentType>DocumentType_0</ns0:DocumentType> 
     // <ns0:StreamArray>GpM7</ns0:StreamArray> 
     //</ns0:AttachedDocument> 
     XNamespace nsAttachedDoc = XNamespace.Get(@”http://BT.Schemas.Internal/AttachedDocument”); 
     XDocument AttachedDocMsg = new XDocument(
             new XElement(nsAttachedDoc + “AttachedDocument”, 
             new XAttribute(XNamespace.Xmlns + “ns0″, nsAttachedDoc.NamespaceName), 
              new XElement(nsAttachedDoc + “FileName”, “FileName_0″), 
              new XElement(nsAttachedDoc + “FilePath”, “FilePath_0″), 
              new XElement(nsAttachedDoc + “DocumentType”, “DocumentType_0″), 
              new XElement(nsAttachedDoc + “StreamArray”, dataOut) 
              ) 
             ); 
     dataOut = AttachedDocMsg.ToString(); 
     TraceManager.PipelineComponent.TraceInfo(“Created AttachedDoc msg = ” + AttachedDocMsg, callToken); 
     MemoryStream ms = new System.IO.MemoryStream(System.Text.Encoding.ASCII.GetBytes(dataOut)); 
     IBaseMessage outmsg = pc.GetMessageFactory().CreateMessage(); 
     outmsg.Context = pc.GetMessageFactory().CreateMessageContext(); 
     // Iterate through inbound message context properties and add to the new outbound message 
     for (int contextCounter = 0; contextCounter < inmsg.Context.CountProperties; contextCounter++) 
     { 
      string Name; 
      string Namespace; 
      object PropertyValue = inmsg.Context.ReadAt(contextCounter, out Name, out Namespace); 
      // If the property has been promoted, respect the settings 
      if (inmsg.Context.IsPromoted(Name, Namespace)) 
      { 
       outmsg.Context.Promote(Name, Namespace, PropertyValue); 
      } 
      else 
      { 
       outmsg.Context.Write(Name, Namespace, PropertyValue); 
      } 
     } 
     outmsg.AddPart(“Body”, pc.GetMessageFactory().CreateMessagePart(), true); 
     outmsg.BodyPart.Data = ms; 
     pc.ResourceTracker.AddResource(ms); 
     outmsg.BodyPart.Data.Position = 0; 
     TraceManager.PipelineComponent.TraceInfo(“END PIPELINE PROCESSING”, callToken); 
     TraceManager.PipelineComponent.TraceOut(callToken); 
     return outmsg; 
    }