Unable to update ServiceReference or add again after deleting? - c#

I have a web app project and silverlight project in the solution. I have WCF file in web app, and I get the below error while updating the ServiceReference
There was an error downloading 'http://localhost:5678/DataForSilverlight.svc/_vti_bin/ListData.svc/$metadata'.
The request failed with HTTP status 404: Not Found.
Metadata contains a reference that cannot be resolved: 'http://localhost:5678/DataForSilverlight.svc'.
The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server error.
If the service is defined in the current solution, try building the solution and adding the service reference again.
I also tried to Delete it and add it again, and I also tried deleting WCF file from web application.

This error usually happens when you're exposing the web application (and then your WCF service) through IIS, using a dynamic port, that changes every time you start and stop the debugging of the solution.
To avoid this problem, right click on the Web project and select 'Properties'. Select the tab 'Web'. In the groupbox named 'Servers', insert your desired network path and click the button 'Create Virtual Directory'. IIS will create a virtual directory for your web project.
Now you can add your service reference to the Silverlight project. The next time you execute the web project, the IIS will execute the web application using the desired network path.
Also, make sure that in the class definition of your service the following attributes are declared:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class DataForSilverlight
and that the following line is existing in your Web.Config file, in <system.serviceModel> section:
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>

Dont know why but i again changed the variable type in the Method which was befor change is
[OperationContract]
void SaveData(int UserId, string FileName, ExtendedImage File);
later changed it to string
[OperationContract]
void SaveData(int UserId, string FileName, string File);
and everything works fine now

Related

Are Web Service References necessary in all project?

I currently have one Web Service in a solution of multiple projects. Since I don't want to add service references in all project to be able to use it, I have created a project with static a class named "ServiceHelper" for the moment. This project would be the only one with the service references and the helper would do all the request ncessary. The Web Service is set public (not internal).
My problem here is that when I initialize my SoapClient in my helper from another project that do not have the service references, it throws an exception. But when I add the service reference to that other project, it works. Is it normal or not?
The exception throwed translated (because it is said in French) is :
Unable to find an element endpoint default refers to the contract 'ServiceReference.WebServiceSoap' section in the ServiceModel client configuration. This may be due to the fact that the configuration file of your application is not found or the endpoint element matching this contract is found in the client element
Is there something missing in my config file? because I didn't change anything in the 2 projects mentionned.
Exemple of how I initialize my SoapClient in my helper :
private static ServiceReference.WebServiceSoapClient _webService = new ServiceReference.WebServiceSoapClient();
Following on with #zverev.eugene, you don't need the references in every project, but the web.config or app.config in the project is where the connection and configuration information is retrieved from. This is because the application calling your class library is what supplies all configuration information (e.g., if you have a data access layer in a class library, the connection string would come from the .config of the application calling the DAL, not the class library itself).

Host WCF in Windows Forms: Error when opening the host

I am trying to start and stop a WCF service library through a windows desktop application but got stuck. I cannot start it because it gives me error in the shost.Open();
Code:
private void startwcfedcHost()
{
ServiceHost shost = new ServiceHost(typeof(WcfServiceLibrary.Service));
shost.Open();
}
Error:
Service 'WcfServiceLibrary.Service' has zero application (non-infrastructure)
endpoints.
This might be because no configuration file was found for your application, or because no service element matching the service name could be found in the configuration file, or because no endpoints were defined in the service element.
But when I try to run my wcf service it works, How can I fix this issue?
Since you don't specify the endpoints via code, you need to specify them via configuration. What you probably have is a missing configuration file. Change the Main method (if a console application; something like the Page_Loaded event if you're writing a windows app) to print the following value:
AppDomain.CurrentDomain.SetupInformation.ConfigurationFile
That will show the name that the application expects its configuration file to be. Once you have that, make sure that that file exists, and it has the appropriate <system.serviceModel> section to define the service endpoints.
I suggest you take a look at the following:
Here
WCF is about A(address) B(binding) C(contract), you need to specify binding.

visual studio 2010 web service

can not find the new way of referencing / using the web service.
there is the old way of adding WEB REFERENCE (.net 2.0) but I would like to use the new service reference.
following tutorial: http://sarangasl.blogspot.com/2010/09/create-simple-web-service-in-visual.html or: http://www.youtube.com/watch?v=qOqEKpYbTzw I can do it the old way. and calling the web reference like they say works - but how to do it with a SERVICE REFERENCE instead.
I can make the service reference itself, but don't know how to use it.
anyone can help find a tutorial? or knows what code to use instead of:
(code for: .net 2.0 - web reference)
service1.Service1 s1 = new service1.Service1();
String result s1.HelloWorld();
Trace.WriteLine(result);
(code for: .net 4.0 - service reference)
here is what i tried
Service1.Service1SoapClient s1 = new Service1.Service1SoapClient();
String result = s1.HelloWorld();
Trace.WriteLine(result);
but it gives an error:
Could not find default endpoint element that references contract 'Service1.Service1Soap' 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.
If you are referring how to add the old asmx style references in vs2010
Right click references and select "Add Service Reference"
then click "Advanced", then click "Add Web Reference"
For a wcf service just simply right click and say "add reference"
to use it - enter in the name of your class. Since I don't know your namespace you may have to include an imports at the top. But basically -
ServiceReference1.WhateverClient cleint = new ServiceReference1.WhateverClient();
When you do ServiceReference1 in your code, you should see the class name that was generated. You just create an instance of that and call it.
The missing paramerters in your class invocation, are in the your Web.Config
Search for the <client> section:
<client>
<endpoint address="http://ioe_test:8080/crypto.asmx" binding="basicHttpBinding"
bindingConfiguration="cryptoSoap" contract="wscol_crypto.cryptoSoap"
name="cryptoSoap" />
</client>
And, the missing parameters are:
endpointConfigurationName corresponds to "name"
remote Address corresponds to "address"
So, in my example should be:
ws_cryp.cryptoSoapClient cryp = new ws_cryp.cryptoSoapClient("cryptoSoap", "http://ioe_test:8080/crypto.asmx");
That should be enough.
Open your app.config and look for the name of the endpoint configuration element generated in there. Then use an overload for the new ServiceClient() call to specify the endpoint.
The issue (found elsewhere) is that I had to move config to the project that initiated the call. Somehow strange (seems out of place now), but now it seems to work.
This is the client section example, in my Web.Config
<client>
<endpoint address="http://ioe_test:8080/crypto.asmx" binding="basicHttpBinding"
bindingConfiguration="cryptoSoap" contract="ws_cryp.cryptoSoap"
name="cryptoSoap" />
</client>
And, the missing parameters are:
endpointConfigurationName corresponds to "name"
remote Address corresponds to "address"
Create a new C# console application project.
Here, I have specified name of the project as “MyFirstWebServiceConsumerApp“.
Click on "Ok" button to proceed further.
Go to Solution Explorer and right click on your Console Application Project Name.
In this case, right click on “MyFirstWebServiceConsumerApp” and select “Add Service Reference…” from the drop down menu.
Click on “Advance” button.
Click on “Add Web Reference..” button.
An Add Web Reference window will appear to consume a web service in c#.net.
Enter here URL of the web service.
Now, click on button(See below image) to retrieve all web service methods in this window.
Enter the Web Service URL and click on -> button to check whether the Web Service URL is valid or not. If the URL is valid, it would show you the available Web Methods and the status will appear as “1 Service Found:”
Enter web service reference name. I used “MyFirstWebServiceReference” as a web service reference name as shown in above image. Now, click on “Add Reference” button..
Now check the Solution Explorer. “MyFirstWebServiceReference” must get added under web reference folder.
The next step is to add Reference of this web service to our c# code, so that we can use this in code files. Add following line in code file consume a web service in c#.net –
using MyFirstWebServiceConsumerApp.MyFirstWebServiceReference;
Add below code to call the web method.
So the final code will appear as:
using System;
using System.Collections.Generic;enter code here
using System.Linq;
using System.Text;
using MyFirstWebServiceConsumerApp.MyFirstWebServiceReference;
namespace MyFirstWebServiceConsumerApp
{
class Program
{
static void Main(string[] args)
{
Service1 webService = new Service1();
Console.WriteLine(webService.MyFirstWebMethod("Dhiraj”, “Kumar”));
Console.ReadLine();
}
}
}
Now save the files and Execute the application. Press F5 button on your keyboard to execute the code. The result should appear as below screenshot –
Your fi­rst web service consumer console application is ready.

Connect to Unknown SOAP Web Service

I would like to build an app in C# that connects to an Apache AXIS web service and performs the following operations via SOAP.
Login in to the server.
POST string data to server
Receive and display server response
Here's the tough part. I do not have access to the server, nor do I know where the .JWS file is located on the server. I was able to get to the WSDL file in my web browser, so I know a "Login" operation exists as well as an operation to take in data.
I have tried accessing the web service via URL, but I keep getting this message:
Hi there, this is an AXIS service!
Perhaps there will be a form for
invoking the service here...
In summary, is there anyway I can connect to this web service when all I have is the URL of the WSDL file? Are web services accessible via URL?
Thank you
Use WCF, and generate client proxies to the web service using the svcutil.exe tool.
running svcutil.exe http://url.to/webservice?WSDL the_wsdl.wsdl /language:C# should generate proxy classes you can use in your C# project, and you'd call the service e.g. like
BasicHttpBinding myBinding = new BasicHttpBinding(); //might not even need these
// 2 lines if you ran svcutil.exe directly on the web service URL
EndpointAddress myEndpoint = new EndpointAddress("http://url.to/webservice");
TestClient client = new TestClient(myBinding,myEndpoint); //the generated classes
// svcutil.exe created
client.SomeOperation(42); // call an SomeOperation of the web service
Thanks for everyone's help. Looking back on this question, I can see how severely confused I was. Here is the solution I followed.
Assuming you know the URL of the WSDL file of the service you wish to connect to then just do the following.
Boot up Visual Studio
On the top toolbar navigate to Data -> Add New Data Source then choose Service in the new dialog
In the address bar, enter the URL of the wsdl file (EXAMPLE: http://server.com/services/displayName?wsdl)
Near the bottom of the dialog, change the namespace to something relevant to the project (EXAMPLE: sampleService)
Now Visual Studio should compile the client proxies for you that you can use to access the web services on your server. To access one of the services, all you need to do is create a new object from the class.
//Example
sampleService.ClassName test = new sampleService.ClassName();
test.displayName("Jack");
See http://msdn.microsoft.com/en-us/library/bb552364.aspx for a starting point

C# SOAP with a custom URL

Okay, simple situation: I'm writing a simple console application which connects to a SOAP web service. I've imported a SOAP Service reference and as a result, my application has a default endpoint build into it's app.config file.
The web service, however, can run on multiple servers and the URL to the proper web service is passed through the commandline parameters of my application. I can read the URL, but how do I connect the web service to this custom URL?
(It should be very simple, in my opinion. It's something I'm overlooking.)
Is this using an auto-generated class deriving from SoapHttpClientProtocol? If so, just set the Url property when you create an instance of the class.
Well, .NET can provide some very useless error messages sometimes. In IIS, the service was configured to AutoDetect cookieless mode. As a result, I had to append "?AspxAutoDetectCookieSupport=1" to the URL. Although that would fix the problem, it was just easier to go to the IIS console, open the properties of the service, go to the ASP.NET tab page, click the "Edit configuration" button, to to "State Management" in the newly popped up screen and change "Cookieless mode" into something other than "AutoDetect"...
Excuse me. Dumb error. Am going to hit myself on the head a few times for this. ;-)
As Jon said, you set the Url, as in:
Namespace.ClassName nwe = new Namespace.ClassName();
nwe.Url = "http://localhost/MyURL/site.asmx";

Categories