Error while consuming WCF from class library from an application deployed on IIS 7.5 - wcf

I am new to WCF services and getting an Error while consuming WCF from Class library, pls correct if i wrong somewhere; I m explaining my problem in steps
1.separate WCF project that is deployed in local IIS, running well from Visual studio(dev env).
2.created CustomClientChannelFactory class and consuming WCF from Business Layer(ie class library)
CustomClientChannelFactory<IPDServices.IIPDServices> objChannelFactory = new CustomClientChannelFactory<IPDServices.IIPDServices>("BasicHttpBinding_IIPDServices", "HISWCFService.config");
IPDServices.IIPDServices obj = objChannelFactory.CreateChannel();
strXML = obj.GetAllAdmittedPatients(strHospitalId);
binding information stored in HISWCFService.config (renamed App.config) and copied in
specified location (C:\Program Files\Common Files\microsoft shared\DevServer\10.0), this is working well on local VS WebDev server while debugging app.
problem started when i deployed App in IIS getting an Error
"The Address property on ChannelFactory.Endpoint was null. The ChannelFactory's Endpoint must have a valid Address specified."
Please suggest

Related

Current Working directory for WCF Application

I have an VB6 com object which i need to wrap it in .net and expose as WCF web service.
The com .dll has some configuration files which needs to be placed in it current directory.
For testing the com object, i have created a console application and executed, from the logs generated by the component i can see that it is pointing to current directory and getting the config files and working as expected.
Now when i host this in WCF service, Com object stoped working. I wondered and gave below command in my wcf application
Logger.Log("current path: " + System.IO.Directory.GetCurrentDirectory());
Now in my log i see that current path is "c:\winnt\system32" !!!!!! And concluded that this might be the reason why the component is not working as expected in wcf.
Note: I have published my wcf into another folder in "d:" drive.
My Question :
What is the reason behind "c:\winnt\system32"?
Thanks for your help!
[Update]
Now it gets wierd, I have changed current directory with below method.
System.IO.Directory.SetCurrentDirectory()
Now the dll points to below path
C:\WINNT\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\service\b5fc8f06\28f29236\assembly\dl3\1945abc0\00563626_8b5bce01\

WCF Enterprise Library ExceptionHandling failing when faultcontracttype in other project

Background: I have a WCF project that is using Microsoft Enterprise Library WCF Exception Handling.
We recently decided to move our operation and data contracts into a separate project (.net assembly) called comanynamespace.xxx.WCF.Utilities. After moving the operation and data contracts, I changed the faultContractType namespace to reflect the new assembly.
Now when I launch the web service in VS2010 I get the following error:
Activation error occured while trying to get instance of type ExceptionPolicyImpl, key "WCF Exception Shielding"
I have tried: ensuring the same references exist in both projects and ensuring that both projects are running under .net 4 (no client modes), etc. Neither helped resolve the issue.
Finally, I copied the Service Fault class back into the Web Service project and changed the namespace in the web.config to point back to the local namespace:
from:
faultContractType="comanynamespace.xxx.WCF.Utilities.ServiceFault, comanynamespace.xxx.WCF.Utilities.Services"
to:
faultContractType="comanynamespace.xxx.Web.Services.ServiceFault, comanynamespace.xxx.Web.Services"
This does resolve the error, however, now I must have my service fault data contract in both locations.
Does anyone know why I am unable to use a service fault (data contract) in another .net assembly with Microsoft EL WCF Exception Handling?
The problem ended up being that the namespace (second part) of the faultcontracttype was set to
faultContractType="companyname.xxx.WCF.Utilities.Services.ServiceFault, companyname.xxx.WCF.Utilities.Services"
instead of
faultContractType="companyname.xxx.WCF.Utilities.Services.ServiceFault, companyname.xxx.WCF.Utilities"
companyname.xxx.WCF.Utilities is the namespace for the assembly.

error while consuming WCF service from VB6 script

I got a simple WCF service written in C#. I need to consume the service from VB script using MS SOAP Toolkit 3.0. I wrote a simple client code like that:
Dim client
Set client = CreateObject("MSSOAP.SoapClient30")
client.MSSoapInit "http://localhost:8888/MyService.svc?wsdl"
I am hosting my service on IIS 7.5 (Windows 7). The error shows up during .MSSoapInit invocation:
HRESULT=0x1: result 0x1 incorrect function.
- WSDLReader:Could not find '/definitions/service' inside the 'default' namespace of the wsdl file HRESULT=0x80070057: The parameter is incorrect.
WSDLReader:Analyzing the WSDL file failed HRESULT=0x80070057: The parameter is incorrect.
Client:One of the parameters supplied is invalid. HRESULT=0x80070057: The parameter is incorrect.
If i run project from Visual Studio (ASP.NET development server) i don't have any troubles, i can consume service from my client code. Generated wsdl-schemas are equal for both cases (except the port number)
What could be a reason of this behaviour?

WCF service reference in class library

I added wcf service (exposed by biztalk) proxy and app.config file in VS 2005 class library project and i am calling this class library methods from windows application. In this case getting error while creating service instance, so i moved app.config file from class library to window applcation, now working fine.
Question: If i will change service url from machine001 to machine002 in config file (from bin folder but not from application) and run the app from exe file. Will it work without build.
Class library configuration always depends on configuration file (web.config / app.config) of parent application that is really using it. And Parent application should be a console / winform / ASP.NET application and can be a windows service. Any change in WinForm's app.config will change the behavior of your class library.
To Answer your question, Yes if you change service url from machine001 to machine002 in config file of windows application it will work if machine002 is hosting the WCF service.
Hope it clears your doubt.

Error message from svcutil.exe - what does it mean?

I've had not a lot of luck creating a WCF service with Visual Studio. It's in IIS, and it I click 'browse' on the .svc file itself, it tells me I have created a service. So I assume it's all okay to a point.
Throughout my time I came across a recommendation to use a program called svcutil.exe. I used it on my service and got the following error. I don't know what it means, so hopefully someone can shed some light on the situation.
Here's the result:
Microsoft (R) Service Model Metadata Tool
[Microsoft (R) Windows (R) Communication Foundation, Version 3.0.4506.2152]
Copyright (c) Microsoft Corporation. All rights reserved.
Attempting to download metadata from 'http://localhost/EvalServiceSite/Eval.svc'
using WS-Metadata Exchange or DISCO.
Error: Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension: System.Se
rviceModel.Description.DataContractSerializerMessageContractImporter
Error: Schema with target namespace 'http://tempuri.org/' could not be found.
XPath to Error Source: //wsdl:definitions[#targetNamespace='http://tempuri.org/'
]/wsdl:portType[#name='IEvalService']
Error: Cannot import wsdl:binding
Detail: There was an error importing a wsdl:portType that the wsdl:binding is de
pendent on.
XPath to wsdl:portType: //wsdl:definitions[#targetNamespace='http://tempuri.org/
']/wsdl:portType[#name='IEvalService']
XPath to Error Source: //wsdl:definitions[#targetNamespace='http://tempuri.org/'
]/wsdl:binding[#name='BasicHttpBinding_IEvalService']
Error: Cannot import wsdl:port
Detail: There was an error importing a wsdl:binding that the wsdl:port is depend
ent on.
XPath to wsdl:binding: //wsdl:definitions[#targetNamespace='http://tempuri.org/'
]/wsdl:binding[#name='BasicHttpBinding_IEvalService']
XPath to Error Source: //wsdl:definitions[#targetNamespace='http://tempuri.org/'
]/wsdl:service[#name='EvalService']/wsdl:port[#name='BasicHttpBinding_IEvalServi
ce']
Generating files...
Warning: No code was generated.
If you were trying to generate a client, this could be because the metadata docu
ments did not contain any valid contracts or services
or because all contracts/services were discovered to exist in /reference assembl
ies. Verify that you passed all the metadata documents to the tool.
Warning: If you would like to generate data contracts from schemas make sure to
use the /dataContractOnly option.
I think this previous Stack Overflow question may help with your current question but not necessarily your problem.
Error: Cannot import wsdl:port with svcutil
You've created your WCF service and you've browsed to it in IIS so you're happy that it is working. The purpose of SVCUtil.exe is to generate classes that you can use in an application to interact with the service with compile time information on the contract members and methods.
it performs the exact same function as adding a service reference in visual studio to consume the service.
If your having trouble, i'd suggest just creating a simple console project in visual studio, adding a service reference and giving it the url of the service you've hosted in IIS. Then click "show all files" in the visual studio solution explorer and look at the reference.cs file it gives you. This will show you what information has been consumed from your service.
Edit
Hi Again,
After going through all the comments below I'm starting to see more about your problem. I think you misunderstand what it is your doing when in fact you've already achieved what you want to achieve.
The original project, the one you had with the WCF test client that worked did what you needed. It is a fully fledged WCF Service. All you needed to do was right click the solution in visual studio and publish it. If you then make sure that you make an IIS virtual directory point at your solution, through the publish wizard. Then when you run your project and then browse to that url, that will give you a service to consume for testing purposes.
What you are doing at the moment, creating a WCF project, adding that DLL to a website project is fundamentally wrong: The example you followed, presumably this one :
http://msdn.microsoft.com/en-us/library/ms733766.aspx
is about creating a WCF service in a web site project from scratch. Not about adding a pre-existing WCF project and hosting it.
Your essentially trying to do one thing in two different ways together.
Your current course of action is to either remove the DLL in your web project and then create the service there. Or host your current WCF service in IIS ( the project you downloaded from me or your original one)
At this point you have a hosted service. Then usually you have an application to interact wtih it. This you found using svcutil and can be done in one of two ways:
You create the console application and do "Add Service Reference" to the URL you have hosted in IIS.
Or you use SVC Util.exe point it at the url which generates a class file you include in your console / application.
I hope that clears things up about WCF and what stages to use various tools?
Edit 2
Just in case you don't get to the Chat:
I still think theres something wrong with your original project. I'm not sure what you mean by the one with the DLL either? if that means your website project with the dll of the WCF project, then no not that one.
I've taken the project I sent you earlier. I've hosed that in IIS so that when i browse to localhost/EvalService on my machine i get the standard
"EvalService Service
You have created a service.
To test this service, you will need to create a client and use it to call the service. You can do this using the svcutil.exe tool from the command line with the following syntax:"
Once I had that set up i created a console application, "added service reference" in visual studio and it consumed teh service no problem.
Try doing the above with the project I sent you and see how far you get.