views:

252

answers:

1

Hi,

I have a WCF service that will be called from a HTML form located in the customer's network.

When the same form is posting the exact same data to an ASP page it expects a response like:

Response.Write "SUCCESS" & vbnewline

How can I send the same response from my WCF service?

Thanks.

+3  A: 

A WCF service can return any type of data, really. That covers basic primitive types like int or string, but you can also create more advanced composite types (classes) and send them back.

HOWEVER: WCF is not designed to return HTML markup - that would be the totally wrong approach to things. WCF is a service - a service provides some functionality, you send in some data/parameters, you get back some data/output types.

WCF should not and must not ever be concerned with the actual representation of that data on the user's end - that's the job of your user interface - the ASP page or whatever you're dealing with.

So you could have a WCF service like this:

[ServiceContract]
interface IMyService
{
  [OperationContract]
  string SomeServiceMethod(string someInput);
}

and then call that from your client code something like this:

string result = MyService.SomeServiceMethod("Hello!");

but you should not ever write a WCF service that returns HTML markup or any other system-specific information.

And since WCF is a message-based system, the WCF service has absolutely no connection to your ASP page - it cannot participate in the ASP lifecycle or access the "Response" object or anything like that.

marc_s
I'd vote this up several times if I could. Amen.
Terry Donaghe
Mark,You absolutely right.Maybe is not wise to use WCF for something like this.I don't control the ASP form that posts to my service, which is located at the customer's servers and I can't change it.The client is looking for the word SUCCESS otherwise it thinks the call to my service failed..I can use a ASP page to accept the call but I wanted to use WCF for the perfomance.
anon2009
@anon2009: you can definitely return a string from your WCF service and make it "SUCCESS" to signal successful completion.
marc_s
Let me try it, I let you know....
anon2009
It didn't work.Maybe it has to do with the fact that I'm using REST. [OperationContract] [WebInvoke( Method = "POST", BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "/Upload")] string GetLogFile(Stream LOGFILE);
anon2009
Actually doing this it works: ebOperationContext.Current.OutgoingResponse.ContentType = "text/xml"; WebOperationContext.Current.OutgoingResponse.StatusDescription = "SUCCESS"; return "SUCCESS";
anon2009
@anon: ok, great to know it works after all! .-)
marc_s