您的位置:首页 > 编程语言 > C#

由WSDL文件生成WEB service server端C#程序

2012-01-18 10:57 387 查看
一般一个已经实现功能的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文件;

wsdl.exe /si ctcc_common_faults_2_0.wsdl ctcc_common_types_2_1.xsd ctcc_mm_notification_interface_2_2.wsdl ctcc_mm_notification_service_2_2.wsdl ctcc_mm_types_2_2.xsd//------------------------------------------------------------------------------
// <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文件.

将自动生成的Service类改为从加入的Interface接口类派生,并实现所有的接口函数.(注意名空间一致)using System;
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;
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();
}}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: