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 {}
[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 >
< 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( 1, 2);
svc.ClientCredentials.UserName.UserName = " MyUserName ";
svc.ClientCredentials.UserName.Password = " MyPassword ";
label1.Text =svc.Add( 1, 2);
WCF整个使用方法对比起WSE就简单很多了.
但作为客户端来说,我粗略测试了性能, 和WSE差不多,WCF还略慢一点.