2 u012599058 u012599058 于 2013.11.28 09:17 提问

C#带附件的soap消息怎么处理

下面是WSDL文件使用命令生成的service.cs文件
//------------------------------------------------------------------------------
//
// This code was generated by a tool.
// Runtime Version:4.0.30319.296
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
//
//------------------------------------------------------------------------------

using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Serialization;
using System.Net;
using System.Net.Mail;

//
// This source code was auto-generated by xsd, Version=2.0.50727.1432.
//

///
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.1432")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Web.Services.WebServiceBindingAttribute(Name="SendMessageBinding", Namespace="http://www.csapi.org/wsdl/parlayx/multimedia_messaging/send/v2_4/service")]
public partial class SendMessageService : System.Web.Services.Protocols.SoapHttpClientProtocol {

private System.Threading.SendOrPostCallback sendMessageOperationCompleted;

private System.Threading.SendOrPostCallback getMessageDeliveryStatusOperationCompleted;

private RequestSOAPHeader requestSOAPHeaderValueField;
/// <summary>
/// 此处是手动添加的
/// </summary>
 public RequestSOAPHeader RequestSOAPHeaderValue
{
    get
    {
        return this.requestSOAPHeaderValueField;
    }
    set
    {
        this.requestSOAPHeaderValueField = value;
    }
}


/// <remarks/>
public SendMessageService() {
    this.Url = "http://localhost:9080/SendMessageService/services/SendMessage";
}

/// <remarks/>
public event sendMessageCompletedEventHandler sendMessageCompleted;

/// <remarks/>
public event getMessageDeliveryStatusCompletedEventHandler getMessageDeliveryStatusCompleted;

/// <remarks/>
[System.Web.Services.Protocols.SoapHeaderAttribute("RequestSOAPHeaderValue")]

//此处也是手动添加的,需要和消息体绑定一起发出去
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Bare)]
[return: System.Xml.Serialization.XmlElementAttribute("sendMessageResponse", Namespace="http://www.csapi.org/schema/parlayx/multimedia_messaging/send/v2_4/local")]
public sendMessageResponse sendMessage([System.Xml.Serialization.XmlElementAttribute("sendMessage", Namespace="http://www.csapi.org/schema/parlayx/multimedia_messaging/send/v2_4/local")] sendMessage sendMessage1) {
object[] results = this.Invoke("sendMessage", new object[] {
sendMessage1});
return ((sendMessageResponse)(results[0]));
}

-----------------自定义类-----
Class A{

public RequestSOAPHeader createSendMessageHeader()
{.....}
public sendMessage createSendMessageBody()
{.....}

public sendMessageResponse sendA(){

sendMessageResponse response=new service().sendMessage();

}

}

-----------------发出的SOAP样例格式是:

soapenv:Header

35000001
35000001000002

/soapenv:Header
soapenv:Body

tel:8613507551001
/soapenv:Body
/soapenv:Envelope

--------现在想绑定附件,格式包括文本、图片、其他等---样例码流如下添加文本附件,文本内容为123456:

POST http://127.0.0.1:14387/SendMessageService HTTP/1.1
Accept-Encoding: gzip,deflate
SOAPAction: ""
Content-Type: multipart/related; type="text/xml"; start="rootpart@soapui.org"; boundary="----=_Part_0_19433180.1385518149361"
MIME-Version: 1.0
User-Agent: Jakarta Commons-HttpClient/3.1
Host: 10.137.73.133:46632
Content-Length: 1243

------=_Part_0_19433180.1385518149361
Content-Type: text/xml; charset=UTF-8
Content-Transfer-Encoding: 8bit
Content-ID: rootpart@soapui.org


soapenv:Header

35000001
35000001000002

/soapenv:Header
soapenv:Body

tel:8613507551001
2222
/soapenv:Body
/soapenv:Envelope
------=_Part_0_19433180.1385518149361
Content-Type: text/plain; charset=us-ascii; name=123.txt
Content-Transfer-Encoding: 7bit
Content-ID:
Content-Disposition: attachment; name="123.txt"; filename="123.txt"

123456
------=_Part_0_19433180.1385518149361--

我知道JAVA可以调用org.apache.axiom.attachments第三方的这个类,但是C#的不知道怎么弄?麻烦知道的大仙告诉小弟下。
同时也需要告诉下,怎么和消息体绑定发出去?是否也要像绑定头一样加个引入什么的?
例如这种: [System.Web.Services.Protocols.SoapHeaderAttribute("RequestSOAPHeaderValue")],但是如果要引入,该怎么引入?

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!