将wcf 以webservice的方式调用
2008-12-26 16:40
295 查看
问题:a公司使用wcf 发布服务(.net Framework 3.0 or 3.5),b公司需要使用a公司发布的服务 ,但b公司目前阶段只使用.net Framework2.0(.net Framework 2.0不支持wcf),如果要调用a公司wcf 服务,那怎么办呢?
一、先上wcf 代码(这里懒得写了,借用microsoft公司发布的wcf samples):
namespace Microsoft.ServiceModel.Samples
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service
name="Microsoft.ServiceModel.Samples.CalculatorService"
behaviorConfiguration="CalculatorServiceBehavior">
<endpoint address=""
binding="basicHttpBinding"
contract="Microsoft.ServiceModel.Samples.ICalculator" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="CalculatorServiceBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
运行,记录服务地址。
二、使用wsdl工具将wcf service生成asp.net webservice方式。
start --->运行--->cmd --->cd C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin 回车。
输入wsdl 服务地址。例(wsdl http://localhost:8571/Service1.svc )便生成相应的类似asp.net webservice代理类的文件。文件地址亦在上面bin中。
新建Console application (net Framework 2.0),添加刚刚生成的代理类。调用:
调用代码:
class Client
Code
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="CalculatorServiceAddress" value="http://localhost:8571/Service1.svc"/>
</appSettings>
</configuration>
运行,即可成功调用。
项目完整代码。http://files.cnblogs.com/yiyisawa/wcfclienttowebservice.rar
(完)
一、先上wcf 代码(这里懒得写了,借用microsoft公司发布的wcf samples):
namespace Microsoft.ServiceModel.Samples
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service
name="Microsoft.ServiceModel.Samples.CalculatorService"
behaviorConfiguration="CalculatorServiceBehavior">
<endpoint address=""
binding="basicHttpBinding"
contract="Microsoft.ServiceModel.Samples.ICalculator" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="CalculatorServiceBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
运行,记录服务地址。
二、使用wsdl工具将wcf service生成asp.net webservice方式。
start --->运行--->cmd --->cd C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin 回车。
输入wsdl 服务地址。例(wsdl http://localhost:8571/Service1.svc )便生成相应的类似asp.net webservice代理类的文件。文件地址亦在上面bin中。
新建Console application (net Framework 2.0),添加刚刚生成的代理类。调用:
调用代码:
class Client
Code
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="CalculatorServiceAddress" value="http://localhost:8571/Service1.svc"/>
</appSettings>
</configuration>
运行,即可成功调用。
项目完整代码。http://files.cnblogs.com/yiyisawa/wcfclienttowebservice.rar
(完)
相关文章推荐
- (转)将wcf 以webservice的方式调用
- 将wcf 以webservice的方式调用
- 使用WebService的方式调用部署在服务器的Wcf服务
- WebService第一种方式发布和调用
- 基于Java的webservice创建与jax-ws方式调用
- 基于Java的webservice创建与soap方式调用
- 用http的方式调用webservice,另,用axis调用
- C#动态调用WCF接口,两种方式任你选。
- WebService学习笔记系列之二----通过wsimport的方式调用WebService
- Jquery以JSON方式调用WebService
- 关于java调用webservice的方式学习
- Webservice的四种客户端调用方式
- 抛弃WebService 在.NET4中jQuery调用WCF
- WCF 客户端调用几种方式
- 客户端调用webservice的两种方式
- .Net下采用GET/POST/SOAP方式动态调用WebService的简易灵活方法(C#)
- Webservice 调用方式整理
- 抛弃WebService,在.NE“.NET研究”T4中用 jQuery 调用 WCF
- C# 调用WebService的3种方式 :直接调用、根据wsdl生成webservice的.cs文件及生成dll调用、动态调用
- WCF 客户端调用几种方式