注意,WCF noobie 警报
我需要创建一个 WCF 客户端来查询非 WCF Web 服务。Web 服务不是 WCF 服务。此外,Web 服务需要客户端身份验证证书。现在,我有了证书,可以创建一个完美运行的非 WCF 客户端;我能够“添加 Web 引用”并打开一个证书对话框以允许我选择适当的证书,然后继续创建 Web 引用。尝试通过“添加服务引用”创建 WCF 客户端是另一回事,它只是因 403 拒绝访问错误而失败。
我有该服务的 WSDL,并已在其上运行 svcutil.exe,但我不确定如何从那里继续。
谢谢你的帮助!
我遇到了一个艰难的情况,即托管在 IBM HTTP Server (IHS) 上的 Java Web 服务端点需要一个 Content-Length 标头,尽管它应该符合 HTTP/1.1。如果我发送标题,一切正常。如果我离开它,我会收到一个 500 错误响应,通知我我的 POST 实体主体是空的(即使它不是)。
我们为这些服务(由第三方开发)在 WCF 客户端上投入了大量时间,但我似乎找不到将 Content-Length 标头附加到请求的好方法。我可以使用 IClientMessageInspector 向请求添加任意标头(即 X-Dan-Lynn-Header),如博客文章中所述,但 WCF 似乎忽略了 Content-Length 标头。
我的选择是:
a) 找出如何强制 WCF 将 Content-Length 标头附加到 HTTP POST 请求,或者,
b) 找到或编写一个极其简单但透明的 HTTP 代理,用 Content-Length 标头装饰请求。
谢谢!
public object BeforeSendRequest(ref Message request, IClientChannel channel)
{
var buffer = request.CreateBufferedCopy(Int32.MaxValue);
var tempRequest = buffer.CreateMessage();
HttpRequestMessageProperty httpRequest = GetHttpRequestProp(tempRequest);
if (httpRequest != null)
{
if (string.IsNullOrEmpty(httpRequest.Headers[HttpRequestHeader.ContentLength]))
{
httpRequest.Headers.Add(HttpRequestHeader.ContentLength, GetMessageLength(buffer).ToString());
httpRequest.Headers.Add("X-Dan-Lynn-Header", …Run Code Online (Sandbox Code Playgroud) 我有一个简单的基于REST的服务,我试图使用ChannelFactory创建一个客户端代理.我希望没有配置文件,所以我试图在代码中执行此操作,我相信我拥有我曾经拥有的.config除了行为.任何人都可以告诉我如何将此配置转换为c#代码:
<behaviors>
<endpointBehaviors>
<behavior name="InitBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
Run Code Online (Sandbox Code Playgroud)
这是我现在已经删除的c#代码:
var endpoint = new EndpointAddress(urlCommServer);
var binding = new WebHttpBinding();
return ChannelFactory<IInitialization>.CreateChannel(binding, endpoint);
Run Code Online (Sandbox Code Playgroud) 我正在创建一个wcf服务,我的wcf服务现在托管在一个控制台应用程序中,如下所示
PersonService = new ServiceHost(typeof(PersonService));
PersonService.AddServiceEndpoint(typeof(IPersonService), binding, "http://localhost:5645/PersonService");
PersonService.Open();
Run Code Online (Sandbox Code Playgroud)
然后我使用ChannelFactory类消耗wcf服务;
EndpointAddress endPoint = new EndpointAddress("http://localhost:5645/PersonService");
ChannelFactory<IPersonService> engineFactory = new ChannelFactory<IPersonService>(binding, endPoint);
IPersonService personChannel = engineFactory.CreateChannel();
Run Code Online (Sandbox Code Playgroud)
然后我可以使用此通道调用方法,如
personChannel.GetPersonById("1");
personChannel.Close();
Run Code Online (Sandbox Code Playgroud)
我的问题是:
如上面的代码所示,在完成工作后关闭通道时,服务始终打开.这是保持服务打开的良好行为,或者我应该打开服务然后在每次呼叫时关闭它,同时考虑到我可能有两个客户同时呼叫同一服务.
请指教.
我有一个WCF的web服务我在我的本地机器上测试,它给了我一个headscratcher.
我的服务配置如下:
<system.serviceModel>
<services>
<service name="GHMDatroseIntegration.GHMDatroseWCFService.DatroseService"
behaviorConfiguration="DatroseServiceBehavior">
<endpoint
address="mex"
binding="basicHttpBinding"
contract="GHMDatroseIntegration.GHMDatroseWCFService.IDatroseService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="DatroseServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)
我的客户端配置如下:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IDatroseService"
closeTimeout="00:02:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:02:00"
allowCookies="false" bypassProxyOnLocal="false"
hostNameComparisonMode="StrongWildcard"
maxBufferSize="524288" maxBufferPoolSize="524288"
maxReceivedMessageSize="524288"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas
maxDepth="32" maxStringContentLength="524288"
maxArrayLength="524288" maxBytesPerRead="524288"
maxNameTableCharCount="524288" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint name="BasicHttpBinding_IDatroseService"
address="http://localhost/DatroseWCFService/DatroseService.svc"
behaviorConfiguration="DatroseServiceBehavior"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IDatroseService" …Run Code Online (Sandbox Code Playgroud) 我必须使用Web服务安全X.509证书令牌配置文件1.1 OASIS标准规范,2006年2月1日,使我的WCF客户端使用Web服务(IBM DataPower)并签署/加密请求.
到目前为止,我已经创建了一个自定义绑定并"思考"我正在沿着正确的方向工作:
更新以反映最新的尝试
Private Function CreateCustomBinding() As Channels.Binding
Dim asbe As New Channels.AsymmetricSecurityBindingElement
asbe.MessageSecurityVersion = MessageSecurityVersion.WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10
asbe.InitiatorTokenParameters = New ServiceModel.Security.Tokens.X509SecurityTokenParameters
asbe.RecipientTokenParameters = New ServiceModel.Security.Tokens.X509SecurityTokenParameters
asbe.MessageProtectionOrder = Security.MessageProtectionOrder.EncryptBeforeSign
asbe.SecurityHeaderLayout = SecurityHeaderLayout.Strict
asbe.IncludeTimestamp = True
asbe.SetKeyDerivation(False)
asbe.DefaultAlgorithmSuite = Security.SecurityAlgorithmSuite.Basic128Rsa15 'By default, AES-128 is used as the encryption algorithm.
'Add the elements to the custom binding
Dim myBinding As New CustomBinding
'element order is important - see http://msdn.microsoft.com/en-us/library/ms733893(v=vs.90).aspx
'Protocol Binding Elements (security)
myBinding.Elements.Add(asbe)
'Encoding Binding Element
myBinding.Elements.Add(New TextMessageEncodingBindingElement(MessageVersion.Soap11WSAddressing10, System.Text.Encoding.UTF8)) …Run Code Online (Sandbox Code Playgroud) 我需要实现一个满足以下 SOAP 消息示例的 WCF 客户端:
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:msa="http://msa.ebs.health.ontario.ca/"
xmlns:idp="http://idp.ebs.health.ontario.ca/"
xmlns:edt="http://edt.health.ontario.ca/"
xmlns:ebs="http://ebs.health.ontario.ca/">
<soapenv:Header>
<ns2:EBS wsu:Id="id-1" xmlns:ns2="http://ebs.health.ontario.ca/" >
<SoftwareConformanceKey>444561ee-277f-77b2-c664-7a9923jfgh1b</SoftwareConformanceKey>
<AuditId>f68e6ff9-74f7-4022-8618-ec2cf0ee4b6a</AuditId>
</ns2:EBS>
<ns2:MSA wsu:Id="id-2" xmlns:ns2="http://msa.ebs.health.ontario.ca/" >
<ServiceUserMUID>4523394</ServiceUserMUID>
<UserID>johndoe</UserID>
</ns2:MSA>
<wsse:Security SOAP-ENV:mustUnderstand="1">
<wsu:Timestamp wsu:Id="id-3">
<wsu:Created>2012-06-26T16:18:15.185Z</wsu:Created>
<wsu:Expires>2012-06-26T16:18:45.185Z</wsu:Expires>
</wsu:Timestamp>
<wsse:UsernameToken wsu:Id="id-4">
<wsse:Username>72214255</wsse:Username>
</wsse:UsernameToken>
<wsse:BinarySecurityToken
EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary"
ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"
wsu:Id="X509-0EE1C2718CEDCA9FC213407274954261">
MIICMzCCAZygAwIBAgIET1e+dDANBgkqhkiG9w0BAQUFADBeMQswCQYDVQQGEwJDQTEQMA4GA1UECBMHT250YXJpbzENMAsGA1UEChMET0hJUDEVMBMGA1UECxMMUmVnaXN0cmF0aW9uMRcwFQYDVQQDEw4xNDIuMTQ1LjcwLjE3NzAeFw0xMjAzMDcyMDAwNTJaFw0xMzAzMDcyMDAwNTJaMF4xCzAJBgNVBAYTAkNBMRAwDgYDVQQIEwdPbnRhcmlvMQ0wCwYDVQQKEwRPSElQMRUwEwYDVQQLEwxSZWdpc3RyYXRpb24xFzAVBgNVBAMTDjE0Mi4xNDUuNzAuMTc3MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCs/JIP6CE5IkfTnD/c56K+QAYqETdLvW1xXJ6ipkVhjjC2ASKuuH4fvhbyxo2B4VugsL9r4E5jHEKoi+GDKOLlLZRfSy0cB8IcpXonAuGqMzhCoEQ1CdxNb9etMyvQGRKEBgniKKxTvpTyZdpYDi92up5E+FYL3jEejhp+1iDFJQIDAQABMA0GCSqGSIb3DQEBBQUAA4GBAHn8VZS169BJMa4E6SNLnY7u80zSh90mbrTUWjM1dEicv3jQMMsrWHfoCt+nRSqfNLUTLc8U0LqiB3jnnNJgJt1T7Sp8eUZPdH0gY3i83ZXA8HDFKMZF3qL8I8ncu8FPcZGYBNhYrGjXXsuqXimiTIjxgm06ErRa/51szOFFxWrB
</wsse:BinarySecurityToken>
<ds:Signature Id="SIG-6" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" >
<ds:SignedInfo>
<ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
<ec:InclusiveNamespaces PrefixList="SOAP-ENV ebs soap-sec soapenv sp tns wsdl wsp wsse wsu xs xsi"
xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" />
</ds:CanonicalizationMethod>
<ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
<ds:Reference URI="#id-1">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
<ec:InclusiveNamespaces
PrefixList="SOAP-ENV ebs soap-sec soapenv sp …Run Code Online (Sandbox Code Playgroud) 我正在使用VSTS2008 + C#+ .Net 3.5来开发IIS中托管的WCF服务.然后,我使用VSTS 2008中的"添加服务引用"功能自动生成客户端代理代码.
我的问题是,假设我创建了一个客户端代理实例,然后使用此特定实例来调用服务器端WCF服务公开的各种方法.那么,每次我进行方法调用时都会建立一个新连接吗?或者客户端和服务器之间会有一个持续的连接(即连接的生命周期是从创建客户端代理实例到处理客户端代理实例)?
我正在使用basicHttpBinding.
我正在为服务(不是WCF)编写WCF客户端。收到未处理的'mustUnderstand'标头元素的错误:{http://www.w3.org/2005/08/addressing}操作,因为请求SOAP包含标有mustunderstand ='true'的标头。我必须将其设置为false或删除整个标题。你能显示出这样做的方法吗?
这是绑定代码
var transportElement = new HttpsTransportBindingElement();
transportElement.AuthenticationScheme = AuthenticationSchemes.Basic;
var messegeElement = new TextMessageEncodingBindingElement();
messegeElement.MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap11);
var binding = new CustomBinding(messegeElement, transportElement);
return binding;
Run Code Online (Sandbox Code Playgroud) 我用WCF服务创建了一个解决方案VS2010 C#,该库获取数据,该服务在解决方案中的控制台应用程序中运行良好.没问题.
对于旧项目,我必须在VS2008项目(以及稍后可能在VS2005上)上使用它.然后我启动VS2010我得到"WCF测试客户端".此时在VS2008中,我尝试在本地计算机上"添加Web引用"...没有结果.
然后我尝试使用Vs2010创建一个控制台应用程序来托管它,我这样做了:
Uri baseAddress = new Uri("http://localhost:8080/hello");
using (ServiceHost host = new ServiceHost(typeof(SecurityAccessWCF.WCFSecurityService), baseAddress))
{
// Enable metadata publishing.
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
host.Description.Behaviors.Add(smb);
host.Open();
Console.WriteLine("The service is ready at {0}", baseAddress);
Console.WriteLine("Press <Enter> to stop the service.");
Console.ReadLine();
// Close the ServiceHost.
host.Close();
}
Run Code Online (Sandbox Code Playgroud)
我得到一个错误Open(),我收到此错误"AddressAccessDeniedException - HTTP无法注册URL ...您的进程没有访问权限"(提供的链接不清楚,我在Win7 x64上作为本地管理员和在域)

wcf ×10
wcf-client ×10
.net ×3
c# ×3
soap ×3
wcf-binding ×2
http-headers ×1
soapheader ×1
wcf-hosting ×1
windows-7 ×1
ws-security ×1