How to Get WCF RIA service URL - asp.net

I have created a WFC RIA Service based on ASP.Net Website and adding the nuget packages for RIA service. I have also created a Service named "FactoryService" by extending DomainService class.
I have tested the service by creating a GridView with DomainDataSource pointing to the service. The service is working.
Now I want to access the service from other clients as I have enabled SOAP endpoint. But I cannot find the service's url to the svc file. I need this url to add service reference to my other projects. How do I find the service url?
I have tried the following urls and all returns 404. (namespace "WebApplication3", DomainService class "FactoryService").
- http://localhost:15066/WebApplication3-FactoryService.svc
- http://localhost:15066/services/WebApplication3-FactoryService.svc
- http://localhost:15066/ClientBin/WebApplication3-FactoryService.svc
- http://localhost:15066/FactoryService.svc
- http://localhost:15066/services/FactoryService.svc
- http://localhost:15066/ClientBin/FactoryService.svc

I have found the problem. In the DomainService class, I missed to annotate it with [EnableClientAccess()].
A domain service class must be marked with the
EnableClientAccessAttribute attribute to make the service available to
the client project. The EnableClientAccessAttribute attribute is
automatically applied to a domain service when you select the Enable
client access check box in the Add New Domain Service Class dialog
box.
As I'm using VS2013, the wizard is not available and missed to annotate it with the attribute.

Normally it has the following form
Base-Address + ClientBin + FullName of DomainService (Namespace+TypeName separated by -)
So in your case it should look like
http://localhost:15066/ClientBin/WebApplication3-FactoryService.svc
When you access this link in a Browser you will be provided a page that looks similar to this
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:
svcutil.exe http://localhost:15066/ClientBin/WebApplication3-FactoryService.svc?wsdl
You can also access the service description as a single file:
http://localhost:15066/ClientBin/WebApplication3-FactoryService.svc?singleWsdl
This will generate a configuration file and a code file that contains the client class. Add the two files to your client application and use the generated client class to call the Service. For example:
C#
class Test
{
static void Main()
{
HelloClient client = new HelloClient();
// Use the 'client' variable to call operations on the service.
// Always close the client.
client.Close();
}
}
Visual Basic
Class Test
Shared Sub Main()
Dim client As HelloClient = New HelloClient()
' Use the 'client' variable to call operations on the service.
' Always close the client.
client.Close()
End Sub
End Class

Related

Call web service and passing a cookie in an ASP.Net Web Application

We have to call a web service hosted by our client. We were able to add a web reference to our ASP.Net web application and use the web service. The client just sent us a text file and said we need to pass this as a cookie to get access to the web service. I ask for their help and they sent me this.
SoapHttpClientProtocol clientProxy = new T();
clientProxy.CookieContainer.Add(uri, cookie);
Is there a way to do this using a web reference? Or do I hav eto make a soap call?
The web reference you have generated should be derived from System.Web.Services.Protocols.SoapHttpClientProtocol (for details see this link). The ancestors of this class also provide a property named CookieContainer so that you can use the following code:
webRefInstance.CookieContainer.Add(uri, cookie);

Insert with Domain Service Object in server side project

I got a basic Silverlight Ria Services solution with 2 projects (Silverlight Client and Asp.net Host) with a Domain Service Class in the Host project.
I can create a new Domain Service object in another class inside the host project, and use the methods generated by Visual Studio.
The query methods of this Domain object works fine retrieving data, but insert methods don't apply to the database, probably cause I didn't submit te operation, as the method "SubmitChanges" does in client project.
Question is: how can I apply insert, delete and update operations with this object in server-side since I'm not coding in Domain Service class, but only using an object of this type?
I've found the method DomainService.Submit, but it requires a ChangeSet that don't know how to provide.
EDIT:
//Client Project (Silverlight):
MyDomain domain = new MyDomain();
domain.Products.Add(new Product());
domain.SubmitChanges(); //sucessfull DB insertion
//Host Project, any new asp.net WebPage:
MyDomain domain = new MyDomain();
domain.InsertProduct(new Product()); //nothing happens in DB
domain.SubmitChanges(); //don't exist
domain.Submit(ChangeSet); //don't know how to provide a ChangeSet
It's done a little bit differently on the server vs. the client. On the server, from your domain service class, you can use Me.ObjectContext to add and save your entities, e.g.
Me.ObjectContext.Products.AddObject(new Product)
Me.ObjectContext.SaveChanges()

how to change the url of web service from localhost to www(word wide web)

i have very simple problem , but the solution are very vast and complex ..
i have one asp.net web service . it is when i run it , url is like this :
http://:56197/Salesforce/SforceService.asmx?wsdl
i want to change it to like this :
http://www.site.com/Salesforce/SforceService.asmx?wsdl
what is mean to say just want to make web service globally and consume web service on remote in cross platform(salesforce)that URL dont to include and pc name of ip name
following suggestion i have tried :
create a wsdl file and export in wsdl format ... but it also include end point address in this format
/Salesforce/SforceService.asmx"/>
again local computer problem , how to modify soap url to access globally
create a proxy class using wsdl tool --> it generate .cs class , if this is right way then how to consume it on client side salesforce
i followed these links :
http://www.justskins.com/forums/dynamically-change-url-in-61352.html
(equivalent done in c#)
Dim rswb as new Testing.Service1()
rswb.URL = "http://Testing/Group/Service1.asmx"
But on service.cs class it doesnot show url proeprty
I am bit of confused and stuck
Please provide me any relative link ..
Thanks
Did you do a web reference or a service reference? I'm thinking you added a service refrence. You might want to change it to a web reference
When you add a reference there is an advanced button. Make sure you select add web reference.
I do this all the time adding a testing web service on my local development machine and switch it to the production one in code.
Dim myWS As New myWS.Update
'//create a new instance of the webservice object
Dim tmpURL as string = "ipaddress/domain name of actual host here"
myWS.Url = "http://" & tmpURL & ".asmx"

Can we expose public properties of a webservice on the client side?

I understand that webservices are stateless. I want to know if there is any way we can expose the public properties (getters and setters) of a webservice on the client side (client side being a vb consumer not javascript)?
Web services are method-based, so they're not designed to access properties.
But there's no reason you couldn't make GetX/SetX methods which are exposed like regular service methods - just make sure you include the [WebMethod] attribute.
As others have suggested, you will need to use get/set methods instead of properties.
As for accessing the web service from JavaScript, just specify the method name in the URL and do an XmlHttpRequest.
The only thing you can "expose" from a web service are the [WebMethod].
You might access your web service with code like the following:
Dim svc as New WebReference.MyWebService()
Dim result As Integer = svc.GetSomeInteger()
svc.SetSomeInteger(result)
Dim result2 As Integer = svc.GetSomeInteger()
You may think that you have created an instance of the web service class. You have not. You have only created an instance of the proxy class in your VB.NET code. In the above code, each call to the web service goes through the same client proxy instance, but will go to a different instance of the server-side web service class.
Even if the web service had properties, or just fields, since you would have a different instance of the web service for each call, you would have a different version of "SomeInteger" each time.

Consuming a Web Service from a Class Library

Using Visual Studio I have a Class Library (C#) where I added a reference to a Service (more preciselly a Web Service).
The Web Service classes and interfaces where generated correctly, and I am trying to consume them using the following code (the web service receives an returns a string):
CallWS request = new CallWS();
request.input = "input string";
WSClient client = new WSClient();
CallWSResponse response = client.CallWS(request);
The last line originates the following exception:
Could not find default endpoint element that references contract 'WS_INTER' 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.
How do I solve this?
You have to add an application configuration file and set up system.serviceModel section defining the address of a service.
You can certainly do that in code. Check this or MSDN for description

Resources