随笔 - 435  文章 - 0  评论 - 111  阅读 - 62万 

WCF的模型和之前.net的WS有所不同. 你在添加Service Reference生成的代理类可以看到

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel""4.0.0.0")]
public partial class MathServiceClient : System.ServiceModel.ClientBase<IMathService>, IMathService {}

 而WCF著名的"ABC"

 

而我们这里调用java系统的WebService,只需要处理Address和Binding

来看看生成的app.config内容,留意黄色高亮的,是我们手工添加修改的.

复制代码
<configuration>
    <system.serviceModel>
        <bindings>            
            <customBinding>
                <binding name="IDrmServiceSoapHttp">
                    <security authenticationMode="UserNameOverTransport" 
                              allowInsecureTransport="true" includeTimestamp="false">
                    </security>
                     <textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
                        messageVersion
="Soap11" writeEncoding="utf-8">
                        <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                            maxBytesPerRead
="4096" maxNameTableCharCount="65536" />
                    </textMessageEncoding>
                    <httpTransport manualAddressing="false" maxBufferPoolSize="524288"
                        maxReceivedMessageSize
="65536" allowCookies="false" authenticationScheme="Anonymous"
                        bypassProxyOnLocal
="false" decompressionEnabled="true" hostNameComparisonMode="StrongWildcard"
                        keepAliveEnabled
="true" maxBufferSize="65536" proxyAuthenticationScheme="Anonymous"
                        realm
="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"
                        useDefaultWebProxy
="true" />
                </binding>
            </customBinding>
            
        </bindings>
        <client>
            
            <endpoint address="http://localhost:8080/oracle-epm-drm-webservices/DrmService"
                binding
="customBinding" bindingConfiguration="IDrmServiceSoapHttp"
                contract
="DRM.IDrmService" name="DrmServicePortType" >
                <headers>
                    <AppParameters xmlns="http://drm.webservices.epm.oracle">
                        <serverUrl>http://DRMServer:5240/Oracle/Drm/APIAdapter</serverUrl>
                        <sessionParams>ProductVersion=11.1.2.1</sessionParams>
                    </AppParameters>
                </headers>
            </endpoint>
            
        </client>
    </system.serviceModel>
</configuration>
复制代码

 调用方法如下:

MathServiceClient svc = new MathServiceClient();
            svc.ClientCredentials.UserName.UserName = "MyUserName";
            svc.ClientCredentials.UserName.Password = "MyPassword";         

       label1.Text =svc.Add(12);               

WCF整个使用方法对比起WSE就简单很多了.

但作为客户端来说,我粗略测试了性能, 和WSE差不多,WCF还略慢一点.

posted on   Gu  阅读(554)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 什么是nginx的强缓存和协商缓存
· 一文读懂知识蒸馏
· Manus爆火,是硬核还是营销?
点击右上角即可分享
微信分享提示