My WinForms VB.NET Application consumes a webservice to perform some queries. When running in debug mode under Visual Studio IDE, it works smoothly, but once deployed in client workstations (or even in my own workstation), it crashes with this message:
System.InvalidOperationException: Could not find default endpoint element that references contract 'MyServiceReference.IMyService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
I guess something that is present when debugging is missing in deployment, but I can't figure out what.
Good fellow S.Dav commented above to alert that I should deploy app.config together with my .exe file to solve this issue. He is correct and if it was an answer, I'd accept it.
Besides, I found that I can hardcode service config data and it will work also.
So I replaced:
Dim myclient as New MyServiceReference.MyServiceClient
by
Dim myclient as New MyServiceReference.MyServiceClient(
New BasicHttpBinding(BasicHttpSecurityMode.None),
New EndpointAddress("http://myservice.mysite.com/services/MyService.svc?wsdl"))
And voilĂ , it worked.
Many thanks for all those who tried and helped with this.
Related
I have tried to google a lot to find a solution to how to host multiple WCF web services on local IIS 6.
So i am asking here. If I can get a step of procedure then i would be glad.
To accomplish your goal this is how to do it:
Create your new solution or just reuse current solution you have.
Create new Project under Visual C# and select WCF Service Application. For sample purposes we name it MultipleHostService project.
It will produce three files named IService1.cs, Service1.svc and Web.config
Under your MultipleHostService project add another New item, under Visual C# Select WCF Service and leave name as is.
It will product addition two files named Iservice2.cs and Service2.svc
Open your Web.Config add Behaviors and Binding configuration highlighted with red box.
If you notice we added Services node and service under it? That is the part that allows us to specify multiple services.
Now click MultipleHostService project
Click Properties
Click Web Tab
In the Servers panel
Select Local IIS in the dropdown list
And under Project URL type this : http://localhost/MultipleHostService "You can change it later on if you want"
And click Create Virtual Directory.
Build the Project MultipleHostService ( Make it sure no failed shown in Error List )
Go to browser and type the follow:
http://localhost/MultipleHostService/Service1.svc
http://localhost/MultipleHostService/Service2.svc
You should see something in the browser like this:
Tools and settings I've used:
Visual Studio 2013
IIS 7
.Net Framework 4.5
Improvements :
You can refactor proper naming for your services.
Remove unnecessary XML node in the configuration file like unused behavior.
Disclaimer : I haven't tested it using IIS 6 but I'm confident that it works on IIS7. Configuration about IIS is not part of this topic so you migt run
some issues which I'm not aware of. There are also some other ways to accomplish multiple hosting of services but this topic is focusing on usage of configuration file. And please do some study on proper Bindings, Behavior and MetaDataExhange which I didn't discuss here.
Does anyone have any tips on how I might track down the root cause of this error:
The type name or alias FooController could not be resolved
I have an ASP.net MVC web application using Unity. My application runs fine locally. However, when I publish the site to a remote server, I get the error above.
I tried on two different remote servers and got the same error. However, when I published the site to a different directory on my local dev box, it works just fine. So, I copied the local working copy to the remote server(s). I get the same exact error. I re-arranged the order of the controllers in the Unity config file and the error will always show the first controller in the file. That is, if I move the type registration for BarController above FooController, the error will show:
The type name or alias BarController could not be resolved
So it appears that anytime a controller is encountered in the Unity configuration file, it fails, but only on the remote servers. It problem doesn't seam to be tied to a specified controller.
Therefore, it seams the problem is environmental. Perhaps the remote servers are missing something in the GAC, that I have on my local dev box. I ran though the references and didn't see anything new added since our last release, but I could be missing something.
Does anyone have any tips on how I can track down the root cause of this problem? The error message doesn't tell me much. I need to know why the FooController could not be resolved.
I solved the problem. I setup a development environment on one of the remote servers. I noticed a problem with one of the references in the web project. The MVC assembly needed to be fixed. So I removed and re-added it. Worked like a charm.
Looking at the change this made, here's what I saw:
The code on the left is my local dev box. It was referencing version 3.0.0.1 and the code on the right is after I fixed the reference on the remote server. It is referencing version 3.0.0.0.
It seams my local dev box had some strange version of ASP.net MVC installed. So I uninstalled it, and reinstalled from the latest published version and republished the code from the local dev build and it worked fine.
After look into this even further, this appears to be the root cause of the problem to begin with:
Windows update caused MVC3 and MVC4 stop working
Recently I've read an article about own WCF binding with Username and Password authentication.
Here is an article: http://webservices20.blogspot.ru/2008/11/introducing-wcf-clearusernamebinding.html.
This project "Clear Username Binding" works well. But the problem for me is that I want the WCF server to be host in WCF Service Host. (Like if you create in VS any service library from the template it will be run in WCF Service Host). I've done the next thing. I've created a new project (service library) and simply copy your service and contract to this new project. Then I copied the app.config system.serviceModel section and added referenced to ClearUserNameBinding project and MyUserNameValidator. That's all
Next, I run the client application. Everything was ok. WCF Service Host had been started and client application ended as I expected. But the problem is that now if I put a breakpoint somewhere in the service implementation (let it be somewhere inside of the EchoString function) and run again I always get a message in VS IDE "Unable to automatically debug WCFServiceLibrary". I really don't know what to do with this error and how to get rid of it, because I need the debugging to be available for me.
P.S. This error is appearing only when I use ClearUserNameBinding. If I use for example wsHttpBinding it works perfect. And of course I have <system.web> <compilation debug="true" /> turned on in my config file
Thanks in advance!
In visual studio put a breakpoint in the first line of the client and attach to the process "WCF service host". Then you could debug into its breakpoints. Not sure how to do it w/o attaching to another process.
Also you could try to use CUB not as a separate binding but as a custom binding. You will need to create the custom binding from code. Pseudo code:
var b = new CustomBinding();
b.elements.add(new TextEncodingElement())
b.elements.add(new SecurityElement() {SecurityMode="UsernameOverTransport"})
b.elements.add(new AutoSecuredHttpTransportElement())
I am using VS2010, and I want to consume a webservice that was given to me
https://www.###################/pinManagement.cfc?wsdl
I have done this many times before but for some reason this one i cant get right
right click, add solution
add service reference
past in url, give a namespace and voila
This pulls in fine, but for some reason a bunch of objects in the wsdl are being left off, namely all the request/response objects. the methods are there, but nothing else.
what am I doing wrong?
Thanks
ok, i solved it. thanks to Ian for the steps to see my error.
i got the solution from this site
http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/51babae5-26e5-4405-b03c-4301710854c0/
but ill repost the steps below incase the link dies
In Visual studio:
1. Click on "Show All Files" in the solution explorer
Open the file named "Reference.svcmap" in your service reference
Set the option UseSerializerForFaults to false in "Reference.svcmap" and save it (please don't update the service reference, apparently doing so will reset the option to true)
Open the Reference.cs and you should see the operations generated
Right click on your web service select:
Configure Service Reference=>Un-check reuse types in referenced assemblies
See if that helps
EDIT ::
Try creating a proxy using the XmlSerializer. You can do that by running svcutil from the command line and then pulling the generated .cs and .config files into your project:
svcutil /serializer:XmlSerializer https://www.example.com/Collections/1x0x0/pinManagement.cfc?wsdl
Any errors that you get from svcutil will probably help you narrow down the problem.
I've set up a WCF Library hosted in a Windows Service using the following walk-through:
http://msdn.microsoft.com/en-us/library/ff649818.aspx
The consumer winforms is in the same solution, which is located locally on my work PC's C: drive.
The walk-through works i.e. the winforms button gives me the correct answer.
If I create a new Solution on the C-Drive with a single Windows Forms project in it I cannot successfully add a service reference to this running service, i get the following message:
The detailed message says the following:
The URI prefix is not recognized. Metadata contains a reference that
cannot be resolved: 'net.tcp://localhost:8526/Service1'. Could not
connect to net.tcp://localhost:8526/Service1. The connection attempt
lasted for a time span of 00:00:02.0020000. TCP error code 10061: No
connection could be made because the target machine actively refused
it 127.0.0.1:8526. No connection could be made because the target
machine actively refused it 127.0.0.1:8526 If the service is defined
in the current solution, try building the solution and adding the
service reference again.
Why can I add this Service Reference ok to a project within the same Solution as the Service but not from a project in a different solution?
EDIT
My colleague found an error in the MSDN article - I have detailed his find HERE
The step by step walkthrough article at MSDN ends unfortunately where it gets interesting, so let's continue here. Because there are many possibilities which may cause the error, I've described several options (= scencarios which may cause the issue) below, which should help troubleshooting:
1st option: Try to specify
net.tcp://localhost:8526/Service1/mex
when you add the service reference to your new client - ensure that the service is installed and running before you do that.
Explanation: The suffix "mex" stands for "metadata exchange" and allows Visual Studio to download details of the WCF contract. This suffix is also used in the walk-through example, it was added automatically (you will see it in the Address field if re-open the added service reference by right-clicking on "Configure Service-Reference...").
2nd option: What I noticed when I tested the walk-through is that it helps sometimes to right-click on the service reference and select in the contect menu "Update Service-Reference".
After a while in the systray you can see the balloon message "Your service(s) have been hosted.", after which you can start the client within the same solution. In this case, the service has been temporarily created but is not deployed permanently - which means, if you stop debugging, it is removed. As a result, you can't use this service from a remote PC, it is just visible within the solution in Visual Studio. Visual Studio internally invokes the tool
WcfSvcHost.Exe /Service:<Service1Binary> /Configuration:<Service1Config>
supporting it with the right parameters to register the service properly (you can find this tool in Visual Studio's Common7\IDE subdirectory, and there is also WcfTestClient.Exe available - a tool which acts as a client, very useful to debug WCF).
For instance, if you have stopped debugging, and launch the client.exe from Windows Explorer outside of Visual Studio, then it does not find the service and you're getting exactly the error message you have described in your question.
There are two interesting links regarding this matter at Microsoft:
Problem with Metadata Exchange and Publishing Metadata
Note that this is different from deploying it as described in the 3rd option.
3rd option: Have you used InstallUtil to deploy the service? In this case it can happen that you have accidently removed the [...]/bin/Debug subdirectory and the service fails to start, because the .EXE file is missing.
Note: This can be avoided if you're using a ServiceInstaller project, which copies the binaries before the service is registered. Or - if you want to use InstallUtil for simplicity - you can copy the service binaries to a target directory (including the .config files and .dlls) before you register it.
4th option: If you run the service on a remote computer, you need to specify the proper host name or IP address of the host instead of localhost, and you need to ensure that the personal firewall (windows firewall or 3rd party) doesn't block the port 8526 (the port number which was used in the example). Specify an exception to allow this port for incoming and outgoing traffic.
5th and final option (UPDATE): Naming conflict - Service1 is the service but also the class name in the Wcf library. Either fully qualify the class name you're using from the WCF library in the service, i.e. WcfServiceLibrary1.Service1 or rename the class. Whytheq has found it himself with a colleague and as posted it here.
More reading: Check out this article, which I've found recently: "WCF: a few tips". It explains very well troubleshooting WCF. The only change I would made to the console hosting example is to replace the using statement by a
ServiceHost host = new ServiceHost(typeof(Service));
try
{
host.Open();
Console.WriteLine("WCF Service is ready for requests." +
"Press any key to close the service.");
Console.WriteLine();
Console.Read();
Console.WriteLine("Closing service...");
}
finally
{
if (host!=null) {
host.Close();
host=null;
}
}
If you want to know more about the reason why, check out this article: "Proxy open and close".
You can get round this as follows:
Browse the service's WSDL URL and save the WSDL to a local file.
Then make the following changes to the file:
Remove the namespace prefix from the name used for the wsdl:binding i.e. change
name="wb:wsclocks-inboundSoapBinding" to be
name="wsclocks-inboundSoapBinding"
Change the binding attribute of the wsdl:port attribute to match, and also remove the namespace prefix from the value of the name attribute, so it is just wsclocks-inbound.
Then run svcutil /o:Client\WBServices /noConfig