看一个实例:
新建个会员管理服务:
[ServiceContract]
public interface IClientManager
{
[OperationContract]
ClientEntity UpdateClientInfo(ClientEntity entity);
}
定义个实体:
[DataContract]
public class ClientEntity
{
[DataMember]
public string ClientName
{
get;
set;
}
}
服务实现:public class ClientManagerService : IClientManager配置服务:
{
public ClientEntity UpdateClientInfo(ClientEntity entity)
{
entity.ClientName="a";
return entity;
}
}
<system.serviceModel>添加引用服务:
<services>
<service name="ClientManagerService">
<endpoint address="http://localhost:8899/ClientManagerService.svc" binding="basicHttpBinding"
contract="IClientManagerService" bindingName="ClientManagerEndPoint"></endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
客户端调用:
ClientManagerProxy.ClientManagerClient proxy = new ClientManagerProxy.ClientManagerClient();
ClientManagerProxy.ClientEntity entity=new ClientManagerProxy.ClientEntity();
entity.ClientName="newValue";
proxy.UpdateClientInfo(entity);
总结,在添加引用服务的时候 IDE 会自动构建创建服务代理的一切信息、包括实体,
1,你可以通过svcutil 生成客户端代理类和数据契约;
2,可以通过项目的"添加服务引用",在你的项目中生成客户端代理类和数据契约;
3,通过将服务器的类定义作为DLL或源代码引入到你的客户端项目中;
4,可以通过WSDL,手动编写相应的参数的SOAP格式的XML片断;