HighTechTalks DotNet Forums  

Converting an endpoint from a config file to code

Dotnet Framework (Webservices) microsoft.public.dotnet.framework.webservices


Discuss Converting an endpoint from a config file to code in the Dotnet Framework (Webservices) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
michael sorens
 
Posts: n/a

Default Converting an endpoint from a config file to code - 01-02-2008 , 01:25 PM






As a baseline, I have a working client and service, each of which uses an
app.config file to specify the connections in the <system.serviceModel>
section.

What I need to do, however, is connect to the WCF service via a COM
interface. As I see it, my client then does not have access to the
configuration file so I must convert it to equivalent code. Below I show the
original <system.serviceModel> section from app.config, followed by the code
I have written so far. I have not found how to hook in the <endpointBehavior>.

As I write this the service is down so I cannot run my latest trial;
however, the error from my prior run was:
"System.IdentityModel.Selectors.PolicyValidationEx ception: The incoming
policy could not be validated." That led me to think I might need to
explicitly say something about the endpointBehavior...

Am I on the right track? What code am I missing? I should mention that this
is my first plunge into WCF and it is still quite murky to me.


The original configuration:
========================================
<system.serviceModel>
<client>
<endpoint address="http://.../Services/ClientService"
behaviorConfiguration="ClientServiceBehavior"
binding="wsFederationHttpBinding"
bindingConfiguration="ClientServiceHttpBinding"
contract="...Service.WCF.Interfaces.IClientService "
name="ClientServiceHttpBinding_IClientService">
<identity>
<dns value="MyServices.com" />
</identity>
</endpoint>
</client>
<bindings>
<wsFederationHttpBinding>
<binding name="ClientServiceHttpBinding"
maxReceivedMessageSize="524288">
<security mode="Message">
<message algorithmSuite="Default" issuedKeyType="SymmetricKey"

issuedTokenType="http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1"
negotiateServiceCredential="true">
<issuer
address="http://.../Services/UsernameSecurityTokenService"
binding="wsHttpBinding"
bindingConfiguration="http://.../Services/UsernameSecurityTokenService">
<identity>
<dns value="AIQSTSServiceAuthorization.com" />
</identity>
</issuer>
<issuerMetadata address="http://.../Services/metaData" />
</message>
</security>
</binding>
</wsFederationHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="ClientServiceBehavior">
<clientCredentials>
<serviceCertificate>
<authentication certificateValidationMode="PeerOrChainTrust"/>
</serviceCertificate>
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
========================================


The code version:
========================================
WSFederationHttpBinding b = new WSFederationHttpBinding();
b.Security.Mode = WSFederationHttpSecurityMode.Message;
b.Security.Message.AlgorithmSuite = SecurityAlgorithmSuite.Default;
b.Security.Message.NegotiateServiceCredential = true;
b.Security.Message.IssuedKeyType = SecurityKeyType.SymmetricKey;
b.Security.Message.IssuedTokenType =
"http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#samlv1.1";
EndpointIdentity identity = EndpointIdentity.CreateDnsIdentity(DNS_IDENTITY);
b.Security.Message.IssuerAddress =
new EndpointAddress(new Uri(SECURITY_ISSUER_ADDRESS), identity);
b.Security.Message.IssuerMetadataAddress =
new EndpointAddress(new Uri(SECURITY_ISSUER_METADATA_ADDRESS), identity);
b.MaxReceivedMessageSize = 524288;

ContractDescription contract = new ContractDescription(CONTRACT_NAME);
ServiceEndpoint m_endpoint = new ServiceEndpoint(
contract, b, new EndpointAddress(MY_URI));
ChannelFactory<IClientService> factory =
new ChannelFactory<IClientService>(m_endpoint);
factory.Credentials.UserName.UserName = USER_NAME;
factory.Credentials.UserName.Password = PASSWORD;

_service = factory.CreateChannel();
ICommunicationObject channel = (ICommunicationObject)_service;
if (channel.State == CommunicationState.Closed) { channel.Open(); }
========================================


Reply With Quote
  #2  
Old   
michael sorens
 
Posts: n/a

Default RE: Converting an endpoint from a config file to code - 01-03-2008 , 05:09 PM






Your afterthought did the trick--binding to a custom app.config file via the
link you provided does indeed work for WCF. That obviates the need for the
whole conversion to code I was slogging my way through.

By the way, I started going down the route of converting the config file to
code because when I researched the question of attaching a config file to a
DLL both my reading and forum posts indicated it could not be done. The
solution you point to here, however, is a way to effectively do it.

Much obliged!

Reply With Quote
  #3  
Old   
Steven Cheng[MSFT]
 
Posts: n/a

Default RE: Converting an endpoint from a config file to code - 01-03-2008 , 09:35 PM



Thanks for your reply,

Glad that it works. Yes, app.config file is application (exe) based, you
can never attach app.config file to a dll/assembly, but associate it with a
certain .NET application domain.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
From: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= <m_j_sorens (AT) newsgroup (DOT) nospam>
Subject: RE: Converting an endpoint from a config file to code
Date: Thu, 3 Jan 2008 14:09:03 -0800

Your afterthought did the trick--binding to a custom app.config file via
the
link you provided does indeed work for WCF. That obviates the need for the
whole conversion to code I was slogging my way through.

By the way, I started going down the route of converting the config file to
code because when I researched the question of attaching a config file to a
DLL both my reading and forum posts indicated it could not be done. The
solution you point to here, however, is a way to effectively do it.

Much obliged!


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.