请教:WCF里如何修改默认命名空间的前缀等
用WCF做出来的效果是:
目标效果是:
问题如下:
1. 怎样将第一行的s:Envelope修改为SOAP-ENV:Envelope;
2. 怎样添加命名空间,现在只有2个,我想增加至目标的5个;
3. 怎样在Inform前增加"cwmp:";
4. 怎样去掉Inform后面的xmlns="urn:dslforum-org:cwmp-1-0"
问题很多,只是看了网上几个例子自己写的,希望各位大大不吝赐教,小女子感激不尽。。。
附件:
一个解决方案里包含两个项目:server和client,code如下:
server端:
using System;
using System.Collections.Generic;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.Xml.Serialization;
using System.Runtime.Serialization;
namespace ACS
{
[DataContract]
public class DeviceIdStruct
{
[DataMember]
public string Manufacturer;
[DataMember]
public string OUI;
[DataMember]
public string ProductClass;
[DataMember]
public string SerialNumber;
}
public class EventList
{
public string EventCode;
public string CommandKey;
}
public class ParameterValueList
{
public string Name;
public string Value;
}
[ServiceContract]
public interface ICwmpBinding
{
[OperationContract(IsOneWay = false)]
uint Inform(DeviceIdStruct DeviceId, EventList Event, uint MaxEnvelopesI, System.DateTime CurrentTime, uint RetryCount, ParameterValueList ParameterList);
}
public class cwmpServiceType : ICwmpBinding
{
public uint Inform(DeviceIdStruct DeviceId, EventList Event, uint MaxEnvelopesI, System.DateTime CurrentTime, uint RetryCount, ParameterValueList ParameterList)
{
Console.WriteLine("Time Now is:{0}!", CurrentTime);
return 1;
}
}
class Program
{
static void Main(string[] args)
{
// 服务器基址
Uri baseAddress = new Uri("http://192.168.20.110:8080/openacs");
// 声明服务器主机
using (ServiceHost host = new ServiceHost(typeof(cwmpServiceType), baseAddress))
{
// 添加绑定和终结点
WSHttpBinding binding = new WSHttpBinding();
binding.Security.Mode = SecurityMode.None;
host.AddServiceEndpoint(typeof(ICwmpBinding), binding, "/acs");
// 添加服务描述
host.Description.Behaviors.Add(new ServiceMetadataBehavior { HttpGetEnabled = true });
try
{
// 打开服务
host.Open();
Console.WriteLine("服务已启动。");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.ReadKey();
}
}
}
}
client端:
using System;
using System.Collections.Generic;
using System.Text;
namespace CPE
{
class Program
{
static void Main(string[] args)
{
WS.CwmpBindingClient client = new WS.CwmpBindingClient();
WS.DeviceIdStruct DeviceId = new WS.DeviceIdStruct();
DeviceId.Manufacturer = "HiTerminal";
DeviceId.OUI = "ABCDEDCBA";
DeviceId.ProductClass = "STB Device";
DeviceId.SerialNumber = "88888888";
WS.EventList Event = new WS.EventList();
Event.EventCode = "0 BOOTSTRAP";
Event.CommandKey = "";
uint MaxEnvelopesI = 5;
DateTime CurrentTime = DateTime.Now;
uint RetryCount = 0;
WS.ParameterValueList ParameterList = new WS.ParameterValueList();
ParameterList.Name = "InternetGatewayDevice.DeviceInfo.SpecVersion";
ParameterList.Value = "1.0";
uint MaxEnvelopesO;
MaxEnvelopesO = client.Inform(DeviceId, Event, MaxEnvelopesI, CurrentTime, RetryCount, ParameterList);
Console.WriteLine("MaxEnvelopes from acs is {0}", MaxEnvelopesO);
Console.ReadKey();
}
}
}
[解决办法]
花时间了解一下useing的用法。