一般一個已經實現功能的WEB Server會發布自己的WSDL文件,供客戶端生成代理類。
但有時是先有的server與client交互的接口定義(WSDL)文件,然后由server和client端分別寫程序,一個提供web服務,一個使用web服務。
以下介紹如何由已有的WSDL文件在VS2008中生成server端代碼。
1)使用VS2008提供的工具wsdl.exe由WSDL文件生成cs文件:
使用wsdl.exe的/serverInterface選項(或縮寫的 /si)指定輸入的wsdl文件(注意,如果要轉換的wsdl文件中import了其他wsdl文件,則所有文件都應列出,包括使用到的xsd文件也應列 出)。輸出將是 一個代碼文件(默認是C#的,如果需要別的語言,參考MSDN中wsdl.exe的使用說明),其中包含每個 wsdl 綁定的接口。
示例:假設ServerInterfaceSample.wsdl文件中import了importedSample.wsdl,並使用Service.xsd作為schema文件;
// <auto-generated>
// 此代碼由工具生成。
// 運行時版本:4.0.30319.235
//
// 對此文件的更改可能會導致不正確的行為,並且如果
// 重新生成代碼,這些更改將會丟失。
// </auto-generated>
// ------------------------------------------------------------------------------
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Serialization;
//
// 此源代碼由 wsdl 自動生成, Version=4.0.30319.1。
//
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute( " wsdl ", " 4.0.30319.1 ")]
[System.Web.Services.WebServiceBindingAttribute(Name= " MessageNotificationBinding ", Namespace= " http://www.chinatelecom.com.cn/wsdl/ctcc/multimedia_messaging/notification/v2_2/s " +
" ervice ")]
public interface IMessageNotificationBinding {
NotifySOAPHeader NotifySOAPHeaderValue {
get;
set;
}
/// <remarks/>
[System.Web.Services.Protocols.SoapHeaderAttribute( " NotifySOAPHeaderValue ")]
[System.Web.Services.WebMethodAttribute()]
[System.Web.Services.Protocols.SoapDocumentMethodAttribute( "", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Bare)]
[ return: System.Xml.Serialization.XmlElementAttribute( " notifyMessageReceptionResponse ", Namespace= " http://www.chinatelecom.com.cn/schema/ctcc/multimedia_messaging/notification/v2_2 " +
" /local ")]
notifyMessageReceptionResponse notifyMessageReception([System.Xml.Serialization.XmlElementAttribute( " notifyMessageReception ", Namespace= " http://www.chinatelecom.com.cn/schema/ctcc/multimedia_messaging/notification/v2_2 " +
" /local ")] notifyMessageReception notifyMessageReception1);
/// <remarks/>
[System.Web.Services.WebMethodAttribute()]
[System.Web.Services.Protocols.SoapDocumentMethodAttribute( "", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Bare)]
[ return: System.Xml.Serialization.XmlElementAttribute( " notifyMessageDeliveryReceiptResponse ", Namespace= " http://www.chinatelecom.com.cn/schema/ctcc/multimedia_messaging/notification/v2_2 " +
" /local ")]
notifyMessageDeliveryReceiptResponse notifyMessageDeliveryReceipt([System.Xml.Serialization.XmlElementAttribute( " notifyMessageDeliveryReceipt ", Namespace= " http://www.chinatelecom.com.cn/schema/ctcc/multimedia_messaging/notification/v2_2 " +
" /local ")] notifyMessageDeliveryReceipt notifyMessageDeliveryReceipt1);
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute( " wsdl ", " 4.0.30319.1 ")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute( " code ")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace= " http://www.chinatelecom.com.cn/schema/ctcc/common/v2_1 ")]
[System.Xml.Serialization.XmlRootAttribute(Namespace= " http://www.chinatelecom.com.cn/schema/ctcc/common/v2_1 ", IsNullable= false)]
public partial class NotifySOAPHeader : System.Web.Services.Protocols.SoapHeader {
private string spRevIdField;
private string spRevpasswordField;
private string spIdField;
private string sANField;
private string transactionIdField;
private string linkIdField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string spRevId {
get {
return this.spRevIdField;
}
set {
this.spRevIdField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string spRevpassword {
get {
return this.spRevpasswordField;
}
set {
this.spRevpasswordField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string spId {
get {
return this.spIdField;
}
set {
this.spIdField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string SAN {
get {
return this.sANField;
}
set {
this.sANField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string transactionId {
get {
return this.transactionIdField;
}
set {
this.transactionIdField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string linkId {
get {
return this.linkIdField;
}
set {
this.linkIdField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute( " wsdl ", " 4.0.30319.1 ")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute( " code ")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace= " http://www.chinatelecom.com.cn/schema/ctcc/multimedia_messaging/notification/v2_2 " +
" /local ")]
public partial class notifyMessageDeliveryReceiptResponse {
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute( " wsdl ", " 4.0.30319.1 ")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute( " code ")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace= " http://www.chinatelecom.com.cn/schema/ctcc/multimedia_messaging/v2_2 ")]
public partial class DeliveryInformation {
private string addressField;
private DeliveryStatus deliveryStatusField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, DataType= " anyURI ")]
public string address {
get {
return this.addressField;
}
set {
this.addressField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public DeliveryStatus deliveryStatus {
get {
return this.deliveryStatusField;
}
set {
this.deliveryStatusField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute( " wsdl ", " 4.0.30319.1 ")]
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Namespace= " http://www.chinatelecom.com.cn/schema/ctcc/multimedia_messaging/v2_2 ")]
public enum DeliveryStatus {
/// <remarks/>
DeliveredToNetwork,
/// <remarks/>
DeliveryUncertain,
/// <remarks/>
DeliveryImpossible,
/// <remarks/>
MessageWaiting,
/// <remarks/>
DeliveredToTerminal,
/// <remarks/>
DeliveryNotificationNotSupported,
/// <remarks/>
AuthPriceFailed,
/// <remarks/>
DrmError,
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute( " wsdl ", " 4.0.30319.1 ")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute( " code ")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace= " http://www.chinatelecom.com.cn/schema/ctcc/multimedia_messaging/notification/v2_2 " +
" /local ")]
public partial class notifyMessageDeliveryReceipt {
private string correlatorField;
private DeliveryInformation deliveryStatusField;
/// <remarks/>
public string correlator {
get {
return this.correlatorField;
}
set {
this.correlatorField = value;
}
}
/// <remarks/>
public DeliveryInformation deliveryStatus {
get {
return this.deliveryStatusField;
}
set {
this.deliveryStatusField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute( " wsdl ", " 4.0.30319.1 ")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute( " code ")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace= " http://www.chinatelecom.com.cn/schema/ctcc/multimedia_messaging/notification/v2_2 " +
" /local ")]
public partial class notifyMessageReceptionResponse {
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute( " wsdl ", " 4.0.30319.1 ")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute( " code ")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace= " http://www.chinatelecom.com.cn/schema/ctcc/multimedia_messaging/v2_2 ")]
public partial class MessageReference {
private string messageIdentifierField;
private string messageServiceActivationNumberField;
private string senderAddressField;
private string subjectField;
private MessagePriority priorityField;
private string messageField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string messageIdentifier {
get {
return this.messageIdentifierField;
}
set {
this.messageIdentifierField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string messageServiceActivationNumber {
get {
return this.messageServiceActivationNumberField;
}
set {
this.messageServiceActivationNumberField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, DataType= " anyURI ")]
public string senderAddress {
get {
return this.senderAddressField;
}
set {
this.senderAddressField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string subject {
get {
return this.subjectField;
}
set {
this.subjectField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public MessagePriority priority {
get {
return this.priorityField;
}
set {
this.priorityField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string message {
get {
return this.messageField;
}
set {
this.messageField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute( " wsdl ", " 4.0.30319.1 ")]
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Namespace= " http://www.chinatelecom.com.cn/schema/ctcc/multimedia_messaging/v2_2 ")]
public enum MessagePriority {
/// <remarks/>
Default,
/// <remarks/>
Low,
/// <remarks/>
Normal,
/// <remarks/>
High,
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute( " wsdl ", " 4.0.30319.1 ")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute( " code ")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace= " http://www.chinatelecom.com.cn/schema/ctcc/multimedia_messaging/notification/v2_2 " +
" /local ")]
public partial class notifyMessageReception {
private string registrationIdentifierField;
private MessageReference messageField;
/// <remarks/>
public string registrationIdentifier {
get {
return this.registrationIdentifierField;
}
set {
this.registrationIdentifierField = value;
}
}
/// <remarks/>
public MessageReference message {
get {
return this.messageField;
}
set {
this.messageField = value;
}
}
}
wsdl.exe /si ctcc_common_faults_2_0.wsdl ctcc_common_types_2_1.xsd ctcc_mm_send_interface_2_2.wsdl ctcc_mm_send_service_2_2.wsdl ctcc_mm_types_2_2.xsd
// <auto-generated>
// 此代碼由工具生成。
// 運行時版本:2.0.50727.3625
//
// 對此文件的更改可能會導致不正確的行為,並且如果
// 重新生成代碼,這些更改將會丟失。
// </auto-generated>
// ------------------------------------------------------------------------------
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Serialization;
//
// 此源代碼由 wsdl 自動生成, Version=2.0.50727.3038。
//
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute( " wsdl ", " 2.0.50727.3038 ")]
[System.Web.Services.WebServiceBindingAttribute(Name= " SendMessageBinding ", Namespace= " http://www.chinatelecom.com.cn/wsdl/ctcc/multimedia_messaging/send/v2_2/service ")]
public interface ISendMessageBinding {
RequestSOAPHeader RequestSOAPHeaderValue {
get;
set;
}
/// <remarks/>
[System.Web.Services.Protocols.SoapHeaderAttribute( " RequestSOAPHeaderValue ")]
[System.Web.Services.WebMethodAttribute()]
[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.chinatelecom.com.cn/schema/ctcc/multimedia_messaging/send/v2_2/local ")]
sendMessageResponse sendMessage([System.Xml.Serialization.XmlElementAttribute( " sendMessage ", Namespace= " http://www.chinatelecom.com.cn/schema/ctcc/multimedia_messaging/send/v2_2/local ")] sendMessage sendMessage1);
/// <remarks/>
[System.Web.Services.Protocols.SoapHeaderAttribute( " RequestSOAPHeaderValue ")]
[System.Web.Services.WebMethodAttribute()]
[System.Web.Services.Protocols.SoapDocumentMethodAttribute( "", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Bare)]
[ return: System.Xml.Serialization.XmlArrayAttribute( " getMessageDeliveryStatusResponse ", Namespace= " http://www.chinatelecom.com.cn/schema/ctcc/multimedia_messaging/send/v2_2/local ")]
[ return: System.Xml.Serialization.XmlArrayItemAttribute( " result ", IsNullable= false)]
DeliveryInformation[] getMessageDeliveryStatus([System.Xml.Serialization.XmlElementAttribute( " getMessageDeliveryStatus ", Namespace= " http://www.chinatelecom.com.cn/schema/ctcc/multimedia_messaging/send/v2_2/local ")] getMessageDeliveryStatus getMessageDeliveryStatus1);
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute( " wsdl ", " 2.0.50727.3038 ")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute( " code ")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace= " http://www.chinatelecom.com.cn/schema/ctcc/common/v2_1 ")]
[System.Xml.Serialization.XmlRootAttribute(Namespace= " http://www.chinatelecom.com.cn/schema/ctcc/common/v2_1 ", IsNullable= false)]
public partial class RequestSOAPHeader : System.Web.Services.Protocols.SoapHeader {
private string spIdField;
private string spPasswordField;
private string timeStampField;
private string productIdField;
private string sANField;
private string transactionIdField;
private EndReason transEndField;
private bool transEndFieldSpecified;
private string linkIdField;
private string oaField;
private string faField;
private bool multicastMessagingField;
private bool multicastMessagingFieldSpecified;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string spId {
get {
return this.spIdField;
}
set {
this.spIdField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string spPassword {
get {
return this.spPasswordField;
}
set {
this.spPasswordField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string timeStamp {
get {
return this.timeStampField;
}
set {
this.timeStampField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string productId {
get {
return this.productIdField;
}
set {
this.productIdField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string SAN {
get {
return this.sANField;
}
set {
this.sANField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string transactionId {
get {
return this.transactionIdField;
}
set {
this.transactionIdField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public EndReason transEnd {
get {
return this.transEndField;
}
set {
this.transEndField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool transEndSpecified {
get {
return this.transEndFieldSpecified;
}
set {
this.transEndFieldSpecified = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string linkId {
get {
return this.linkIdField;
}
set {
this.linkIdField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, DataType= " anyURI ")]
public string OA {
get {
return this.oaField;
}
set {
this.oaField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, DataType= " anyURI ")]
public string FA {
get {
return this.faField;
}
set {
this.faField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public bool multicastMessaging {
get {
return this.multicastMessagingField;
}
set {
this.multicastMessagingField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool multicastMessagingSpecified {
get {
return this.multicastMessagingFieldSpecified;
}
set {
this.multicastMessagingFieldSpecified = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute( " wsdl ", " 2.0.50727.3038 ")]
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Namespace= " http://www.chinatelecom.com.cn/schema/ctcc/common/v2_1 ")]
public enum EndReason {
/// <remarks/>
[System.Xml.Serialization.XmlEnumAttribute( " 0 ")]
Item0,
/// <remarks/>
[System.Xml.Serialization.XmlEnumAttribute( " -1 ")]
Item1,
/// <remarks/>
[System.Xml.Serialization.XmlEnumAttribute( " 1 ")]
Item11,
/// <remarks/>
[System.Xml.Serialization.XmlEnumAttribute( " 2 ")]
Item2,
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute( " wsdl ", " 2.0.50727.3038 ")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute( " code ")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace= " http://www.chinatelecom.com.cn/schema/ctcc/multimedia_messaging/v2_2 ")]
public partial class DeliveryInformation {
private string addressField;
private DeliveryStatus deliveryStatusField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, DataType= " anyURI ")]
public string address {
get {
return this.addressField;
}
set {
this.addressField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public DeliveryStatus deliveryStatus {
get {
return this.deliveryStatusField;
}
set {
this.deliveryStatusField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute( " wsdl ", " 2.0.50727.3038 ")]
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Namespace= " http://www.chinatelecom.com.cn/schema/ctcc/multimedia_messaging/v2_2 ")]
public enum DeliveryStatus {
/// <remarks/>
DeliveredToNetwork,
/// <remarks/>
DeliveryUncertain,
/// <remarks/>
DeliveryImpossible,
/// <remarks/>
MessageWaiting,
/// <remarks/>
DeliveredToTerminal,
/// <remarks/>
DeliveryNotificationNotSupported,
/// <remarks/>
AuthPriceFailed,
/// <remarks/>
DrmError,
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute( " wsdl ", " 2.0.50727.3038 ")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute( " code ")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace= " http://www.chinatelecom.com.cn/schema/ctcc/multimedia_messaging/send/v2_2/local ")]
public partial class getMessageDeliveryStatus {
private string requestIdentifierField;
/// <remarks/>
public string requestIdentifier {
get {
return this.requestIdentifierField;
}
set {
this.requestIdentifierField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute( " wsdl ", " 2.0.50727.3038 ")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute( " code ")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace= " http://www.chinatelecom.com.cn/schema/ctcc/multimedia_messaging/send/v2_2/local ")]
public partial class sendMessageResponse {
private string resultField;
/// <remarks/>
public string result {
get {
return this.resultField;
}
set {
this.resultField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute( " wsdl ", " 2.0.50727.3038 ")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute( " code ")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace= " http://www.chinatelecom.com.cn/schema/ctcc/common/v2_1 ")]
public partial class SimpleReference {
private string endpointField;
private string interfaceNameField;
private string correlatorField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, DataType= " anyURI ")]
public string endpoint {
get {
return this.endpointField;
}
set {
this.endpointField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string interfaceName {
get {
return this.interfaceNameField;
}
set {
this.interfaceNameField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string correlator {
get {
return this.correlatorField;
}
set {
this.correlatorField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute( " wsdl ", " 2.0.50727.3038 ")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute( " code ")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace= " http://www.chinatelecom.com.cn/schema/ctcc/common/v2_1 ")]
public partial class ChargingInformation {
private string descriptionField;
private string currencyField;
private decimal amountField;
private bool amountFieldSpecified;
private string codeField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string description {
get {
return this.descriptionField;
}
set {
this.descriptionField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string currency {
get {
return this.currencyField;
}
set {
this.currencyField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public decimal amount {
get {
return this.amountField;
}
set {
this.amountField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool amountSpecified {
get {
return this.amountFieldSpecified;
}
set {
this.amountFieldSpecified = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string code {
get {
return this.codeField;
}
set {
this.codeField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute( " wsdl ", " 2.0.50727.3038 ")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute( " code ")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace= " http://www.chinatelecom.com.cn/schema/ctcc/multimedia_messaging/send/v2_2/local ")]
public partial class sendMessage {
private string[] addressesField;
private string senderAddressField;
private string subjectField;
private MessagePriority priorityField;
private bool priorityFieldSpecified;
private ChargingInformation chargingField;
private SimpleReference receiptRequestField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute( " addresses ", DataType= " anyURI ")]
public string[] addresses {
get {
return this.addressesField;
}
set {
this.addressesField = value;
}
}
/// <remarks/>
public string senderAddress {
get {
return this.senderAddressField;
}
set {
this.senderAddressField = value;
}
}
/// <remarks/>
public string subject {
get {
return this.subjectField;
}
set {
this.subjectField = value;
}
}
/// <remarks/>
public MessagePriority priority {
get {
return this.priorityField;
}
set {
this.priorityField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool prioritySpecified {
get {
return this.priorityFieldSpecified;
}
set {
this.priorityFieldSpecified = value;
}
}
/// <remarks/>
public ChargingInformation charging {
get {
return this.chargingField;
}
set {
this.chargingField = value;
}
}
/// <remarks/>
public SimpleReference receiptRequest {
get {
return this.receiptRequestField;
}
set {
this.receiptRequestField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute( " wsdl ", " 2.0.50727.3038 ")]
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Namespace= " http://www.chinatelecom.com.cn/schema/ctcc/multimedia_messaging/v2_2 ")]
public enum MessagePriority {
/// <remarks/>
Default,
/// <remarks/>
Low,
/// <remarks/>
Normal,
/// <remarks/>
High,
}
代碼中有一個接口類,並給出了接口函數聲明.
此功能的優點是將實現代碼和協定代碼(如接口所定義的那樣)分開。 如果更改 wsdl,然后重新生成接口,則不會丟失任何實現代碼。 若要遵循建議的設計指南,則不應將任何代碼放置在更改 wsdl 協定的實現中。 同樣,不應使用影響運行時行為的代碼來更改接口。 協定和實現的詳細信息應該分開。
2) 在VS IDE中新建一個web service工程,加入新生成的**Interface.cs文件.
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
/// <summary>
/// WebService 的摘要說明
/// </summary>
[WebService(Namespace = " http://tempuri.org/ ")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// 若要允許使用 ASP.NET AJAX 從腳本中調用此 Web 服務,請取消對下行的注釋。
// [System.Web.Script.Services.ScriptService]
public class WebService : IMessageNotificationBinding
{
private static log4net.ILog _log = log4net.LogManager.GetLogger( " WebService ");
public WebService()
{
// 如果使用設計的組件,請取消注釋以下行
// InitializeComponent();
}
[WebMethod]
public string notifyManagementInfo( string xml)
{
_log.Info( " xml= " + xml + " ,Now= " + DateTime.Now.ToString( " yyyy-MM-dd HH:mm:ss "));
return " Hello World ";
}
public NotifySOAPHeader NotifySOAPHeaderValue
{
get { throw new NotImplementedException(); }
set { throw new NotImplementedException(); }
}
public notifyMessageReceptionResponse notifyMessageReception(notifyMessageReception notifyMessageReception1)
{
throw new NotImplementedException();
}
public notifyMessageDeliveryReceiptResponse notifyMessageDeliveryReceipt(notifyMessageDeliveryReceipt notifyMessageDeliveryReceipt1)
{
throw new NotImplementedException();
}
}
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
/// <summary>
/// WebService2 的摘要說明
/// </summary>
[WebService(Namespace = " http://tempuri.org/ ")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// 若要允許使用 ASP.NET AJAX 從腳本中調用此 Web 服務,請取消對下行的注釋。
// [System.Web.Script.Services.ScriptService]
public class WebService2 : ISendMessageBinding
{
public WebService2()
{
// 如果使用設計的組件,請取消注釋以下行
// InitializeComponent();
}
[WebMethod]
public string HelloWorld()
{
return " Hello World ";
}
public RequestSOAPHeader RequestSOAPHeaderValue
{
get { throw new NotImplementedException(); }
set { throw new NotImplementedException(); }
}
public sendMessageResponse sendMessage(sendMessage sendMessage1)
{
throw new NotImplementedException();
}
public DeliveryInformation[] getMessageDeliveryStatus(getMessageDeliveryStatus getMessageDeliveryStatus1)
{
throw new NotImplementedException();
}
}