How do I specify the contract in C# code? I want to remove dependency on config file, and getting error:
Could not find default endpoint element that references contract 'TFBIC.RCT.HIP. Components.RCTBizTalk.WcfService_TFBIC_RCT_BizTalk_Orchestrations' in the Servic eModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this co ntract could be found in the client element.
<endpoint
address="http://nxwtest08bt1/TFBIC.RCT.BizTalk.Orchestrations/WcfService_TFBIC_RCT_BizTalk_Orchestrations.svc"
binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_ITwoWayAsync"
contract="TFBIC.RCT.HIP.Components.RCTBizTalk.WcfService_TFBIC_RCT_BizTalk_Orchestrations"
name="WSHttpBinding_ITwoWayAsync">
<identity>
<userPrincipalName value="NXWTest08BT1\BTAdmin" />
</identity>
</endpoint>
I'm trying for the first time to use ChannelFactory to specify parms that are normally buried in the config file:
WSHttpBinding myBinding = new WSHttpBinding();
string webServiceURL = "http://localhost/TFBIC.RCT.BizTalk.Orchestrations/WcfService_TFBIC_RCT_BizTalk_Orchestrations.svc";
EndpointAddress myEndpoint = new EndpointAddress(webServiceURL);
ChannelFactory<WcfService_TFBIC_RCT_BizTalk_Orchestrations> myChannelFactory =
new ChannelFactory<WcfService_TFBIC_RCT_BizTalk_Orchestrations>
(myBinding, myEndpoint);
// Create a channel and call the web-service via the channel
WcfService_TFBIC_RCT_BizTalk_Orchestrations wcfClient2 =
myChannelFactory.CreateChannel();
req.PolicyAction = polAction;
resp = wcfClient2.WCFSubmitPolicyAction(req);
propResult = resp.PropertyValuation;
I was using Intellisense with the myEndPoint variable, and couldn't find anything like "contract" or even "bindingConfiguration".
What I'm doing is copying my .exe to a new directory, and total removing the <system.serviceModel>
element/group. I'd like to try to run entirely without the config file. See my related question: http://stackoverflow.com/questions/1711588/nunit-tests-that-call-dlls-that-call-wcf-web-services-net-c. I'm trying to follow Gilham's answer, even though I didn't fully understand it. I figured learning how ChannelFactory works was the first step.
Thanks,
Neal Walters
Additional Config File Section:
<wsHttpBinding>
<binding
name="WSHttpBinding_ITwoWayAsync" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false"
hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192"
maxArrayLength="16384" maxBytesPerRead="4096"
maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />;
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />;
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" establishSecurityContext="true" />
</security>
</binding>
Edits Nov-11, 2009 after 5pm Central Time
The saga continues, based on what @Marc_s said below, I think I finally figured out that putting the contract into the when defining the channel factory. Earlier, I was looking for something like endpoint.contract="xxx", since in the Config file, the contract seemed to be sub-parameter of the endpoint.
//Not-Fully Qualified Contract
//ChannelFactory<WcfService_TFBIC_RCT_BizTalk_Orchestrations> myChannelFactory =
// new ChannelFactory<WcfService_TFBIC_RCT_BizTalk_Orchestrations>(myBinding, myEndpoint);
//Fully Qualified Contract
ChannelFactory<TFBIC.RCT.HIP.Components.RCTWebService.WcfService_TFBIC_RCT_BizTalk_Orchestrations> myChannelFactory =
new ChannelFactory<TFBIC.RCT.HIP.Components.RCTWebService.WcfService_TFBIC_RCT_BizTalk_Orchestrations>(myBinding, myEndpoint);
To get the above to compile, I also has to make a reference to my TBFIC.RCT.HIP.Components (my .DLL Class-Library that calls the WCF service).
So I tried the code above, it runs fine when I have the config file, but still, when I remove the config I get this error:
Could not find default endpoint element that references contract 'TFBIC.RCT.HIP. Components.RCTWebService.WcfService_TFBIC_RCT_BizTalk_Orchestrations' in the Ser viceModel client configuration section. This might be because no configuration f ile was found for your application, or because no endpoint element matching this contract could be found in the client element.
Now, I'm still at a loss what I'm doing wrong to remove the dependencies of the config file. I am now using the exact contract it complains as being missing in the channelFactory definition. Thanks again!