Can't add service reference - c#

I have started learning WCF. I wrote a simple service to query a SQL relation through LINQ.
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = aspNetCompatibilityRequirementsMode.Allowed)]
public class Order_WCFService
{
[OperationContract]
public List<Order> getOrders()
{
List<Order> orderList= null;
try
{
orderList= DAL.GetList<Order>();
return orderList;
}
catch (Exception)
{
throw;
}
}
}
This is located in ASP.NET-MVC project.
I have a simple silverlight application. It's in the same solution, but in a different project.
I would like to consume my service by a silverlight application.
I attempt to "Add Service Reference..." and in the left hand column I have a list of all available ASMX and WCF services. When I click on any of the services, it attempts to download service information, but fails after 10-20 seconds: "An error occured (details) while attempting to find services at..."
What am I doing wrong here?
Thank you
I'm 100% certain that services are functional because I can invoke them through AJAX.

Maybe a stupid question but was the service running when you attempted to add the service reference (if you are using the Visual Studio's built-in web server, was it started and the ASP.NET MVC project containing the service running)? Also you may try giving the full address of the WSDL in the Add Service Reference dialog instead of selecting it from a list after verifying that this WSDL is accessible in your browser.

Related

Recognize WCF solution

I am new in Web Service Developement in .NET. Now I am analyzing a big solution of dozens of projects. There I have project that uses a web service and I want to know if it is a WCF Service or some other kind like Web API...
In the past I used ASMX Web Services in .NET and you were able to recognize a ASMX web service via its file extension. But here I don't see any special extensions in the project. I have read that WCF Services have .svc files if they are hosted in IIS. But this project doesn't have a .svc file. So, what are the main characteristics which distinguish a WCF Service from other web services in .NET.
The structure of the solution is as following:
-Solution
+-CreateDocWebServiceInterface
+-CreateDocWebService
+-...
The CreateDocWebServiceInterface looks like that:
namespace CreateDocWebServiceInterface
{
/// <summary>
/// </summary>
[ServiceContract(Name = "ICreateDocWebService", Namespace = "http://www.standardlife.de/CreateDocWebService")]
[RequiredParametersBehavior]
[ServiceKnownType(typeof(Bookmark))]
[ServiceKnownType(typeof(List<Bookmark>))]
public interface ICreateDocWebService
{
[OperationContract]
byte[] CreateDoc(OutputFormat OutputFormat, bool DuplexPrinting, List<Document> Documents);
}
}
And the CreateDocWebService looks like that:
namespace CreateDocWebService
{
// single threaded, but each request is handled concurrent !
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Single, Namespace = "http://www.blablabla.de/CreateDocWebService")]
public class CreateDocWebService : ICreateDocWebService
{
public byte[] CreateDoc(OutputFormat outputFormat, bool duplexPrinting, List<Document> documents)
{
bla bla bla
}
}
}
It could be a Web Service with Web API, but as I know Web API web services consist of controllers which derive from the ApiController?!(Is this correct and the unique characteristic of Web Api Web Services?)
So is this a WCF Service? And what is the unique characteristic of a WCF service and of an Web API Web Service
It is a WCF Project because your Interface is surrounded by [ServiceContract].
Another way if you want to know if it's a WCF Project or ASP.NET Web Service simply open your project's folders in File Explorer. You can hover over the icon with your mouse and a tooltip will display the project type as shown in the picture. Also, you can look under the Type column in File Explorer and it shows it there as well.
WCF Web Service Project:
ASP.NET Web Service Project:
Also to note, if your project has a Resources.Designer.cs or Settings.Designer.cs in its Properties folder it's likely a WinForms application.

How to pass parameters to SOAP web service using asp.net mvc 4

I want to pass parameters to method in SOAP web service. When an user adds a booking, I want to call smsSend() method in web service.
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult AddBooking(booking bk)
{
if(ModelState.IsValid)
{
db.bookings.Add(bk);
db.SaveChanges();
return RedirectToAction("Index", "Home");
}
return View(bk);
}
I have done lot of googling but nothing worked for me.How do I do that can someone help me to pass parameters to web service.
If you are using Visual Studio, you can add a Service Reference to the external service. Visual Studio will create strongly-typed C# bindings to the reference. You will need the URL of the SOAP service to add it. See the Stack Overflow question here (the process is the same for Web Apps):
How to add a web service reference in Visual Studio 2015 to a console app
The link to the MSDN documentation for the process is here:
https://msdn.microsoft.com/en-us/library/bb628652.aspx
Once you have added the Service Reference, you can use the service by simply adding a using directive containing the namespace you set when you added the service and using the bindings that Visual Studio made for you.
If you do not see Add Service Reference, you may be using a .Net Core project which may not have this ability.
Edited to add information on the specific service you linked:
using SmsTest.SmsService;
namespace SmsTest
{
class Program
{
static void Main(string[] args)
{
var msg = "Your SMS Message";
var serviceProviderId = 42;
// Use the constructor overloads for ServiceClient to configure how to connect
var service = new MyServiceClient();
service.smsSend(serviceProviderId, msg);
}
}
}
This is using the information you provided with my program's default namespace as SmsTest and the Service Reference's namespace as SmsService.

DataContract create in WCF

At client side, I have this class without [DataContract]:
public class UserEntity
{
public string login;
public string password;
}
when I put [DataContract] and refresh the reference of this class at WCF side, then I can't initiate the web service. It says an error:
cannot create metadata...
What's wrong?
Are you sure that you actually know, why you can't refresh the reference? I mean you add [DataMember] - and it fails, you remove it - it works? Or it works several days ago and now you add [DataMember] (and many other stuff) and it not works now?
But anyway, the easiest way to solve "refresh reference" issues - to refresh reference manually with SvcUtil.exe. In this case error message would be much more descriptive the simple "oops! error!".
What is client and server side in your case? What is refreshing reference on the WCF side? Your description is very uncommon. Here is description how to create service with complex data type and WCF Class library:
Create WCF class library
Add data contract to the class library
Add service to class library
Implement service contract and service in the class library
Add host project
Reference WCF class library from host project
Host service from class library in host project
Add Metadata endpoint to your hosted service
Create client project
Run the host project outside the visual studio
Use Add service reference to create proxy on WCF service hosted in your host project
Implment code to call your service through created proxy
As you see there is no modification of data contract on the client side and no refreshing WCF service.

Domain Service vs WCF Service?

Im slowly delving into Silverlight and after a good while trying I am finally able to return my own Custom Object from my web to my silverlight client, use a Siverlight enabled WCF service.
Now, im a little at a loss between the differences of a Domain Service, and a WCF Service.
Ive worked through the tutorials where a Domain Service is tied to a data context then bound to siliverlight controls. Great :) However, where i hit a rock was trying to return anything bar IQuerryable; as String, my own simple type etc.
I found a few tutorials such as this showing to mark a function with the [ServiceContract] annotation and to have a [Key] within your simple class. This didnt work, [ServiceContract] was not resolvable, and i later found a guide saying to use [Invoke]. I then hit issues of not been able to load the function and get a result, i basically go to here
[Invoke]
public string HelloWorld(string name)
{
return string.Format("Hello {0}.", name);
}
var helloWorld = new HelloWorldDomainContext();
//helloWorld.HelloWorldCompleted += new EventHandler<InvokeEventArgs<string>>(HelloWorldHelloWorldCompleted);
//helloWorld.HelloWorld("Mark Monster");
Anyway, so I then discovered silverlight enabled WCF services, and am able to return my own custom objects and call this fine.
tl;dr - Are Domain Services only for use when binding to Silverlight controls? Ie its kind of a direct one way binding and is called as and when is needed, and i do all Linq related sorting / filtering / selecting on the server?
And lets say I want to return an xmlString, then i use a WCF service? Am i right to be using a mix of WCF services and Domain Services in my application?
Sorry if the above is a bit confusing! Just trying to get to grips with this all coming from ASP.NET / Flex
Thanks muchly.
This should clear things up:
WCF RIA Services: Returning a Simple POCO from RIA
Here is what I've found after searching:
http://42spikes.com/post/-Using-WCF-RIA-Services-with-your-POCO-Part-4-Returning-a-Simple-POCO-from-RIA

Using Webservice classes in Silverlight when adding service reference instead of web reference

Scenario:
I am using Silverlight 3.0 as client for a web service.
Design:
The server has a class named DeviceInfoService which has the basic functionality of getting the list of devices, getting the properties of devices etc.
When I open an ASP.NET project and try to add a web reference, I can find an option to add a "Web Reference". After I add the web reference this way, I am able to access the DeviceInfoService class by creating it's object and then accessing it's methods.
Web Reference v/s Service Reference:
Coming to Silverlight: when I try to add a service reference, there is no option to add a web reference. Going with Service Reference, everything works fine till WSDL file is downloaded. People say that I can get this option by going back to .NET 2.0, but probably Silverlight won't work in .NET 2.0
The Problem
Now when I try to access the class DeviceInfoService , I am not able to find it. All I get is Interfaces -- DeviceInfoServiceSoap and DeviceInfoServiceSoapChannel. Classes named DeviceInfoServiceSoapClient.
The methods GetHostedDevices and GetDeviceInfo are no longer available. All I get is GetDeviceInfoRequest, GetDeviceInfoRequestBody, GetDeviceInfoResponse and GetDeviceInfoResponseBody.
I googled a lot how to use these four classes, only to find nothing. I want to get those 2 classes directly like in ASP.NET and not using those Request Response type.
You sound awfully confuse about some concepts.
How about you watch the following Silverlight.Net video and see if that helps?
How to Consume WCF and ASP.NET Web Services in Silverlight
What is web reference in ASP.NET is equivalent to service reference in Silverlight.
Here's an example of how to use a web service in Silverlight, e.g. the CDYNE Profanity Filter.
Add a new Service Reference to your project, URL is: http://ws.cdyne.com/ProfanityWS/Profanity.asmx?wsdl, leave the name as ServiceReference1.
Use this code behind to call the service (which was implemented to be asynchronous):
public MainPage()
{
InitializeComponent();
string badText = "I wonder if the filter will filter this out: shit bad luck";
ServiceReference1.ProfanitySoapClient client = new ServiceReference1.ProfanitySoapClient();
client.ProfanityFilterCompleted += new EventHandler<ServiceReference1.ProfanityFilterCompletedEventArgs>(client_ProfanityFilterCompleted);
client.ProfanityFilterAsync(badText, 0, false);
}
void client_ProfanityFilterCompleted(object sender, ServiceReference1.ProfanityFilterCompletedEventArgs e)
{
string cleanText = e.Result.CleanText; // Web service callback is here
}
And you've got a web service up and running in Silverlight!

Categories

Resources