Consuming the Tridion 2011 linking.svc service in ASP.NET - tridion

I receive the following error when attempting to add a service reference to /linking.svc in my ASP.NET application:
There was an error downloading http://localhost:82/linking.svc/. The request failed with HTTP status 404: Not Found. Metadata contains a reference that cannot be resolved: http://localhost:82/linking.svc/. There was no endpoint listening at http://localhost:82/linking.svc/ that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details. The remote server returned an error: (404) Not Found. If the service is defined in the current solution, try building the solution and adding the service reference again.
I thought I could consume the linking service in the same way as odata (add service reference in Visual Studio) as odata works fine for me. I've checked the web.config of my services installation and both endpoints look correctly configured.
<!-- HTTP support -->
<service name="Tridion.ContentDelivery.Webservice.ODataService">
<endpoint behaviorConfiguration="webHttp" bindingConfiguration="HttpBinding" binding="webHttpBinding" contract="Tridion.ContentDelivery.Webservice.IODataService" />
</service>
<service name="Tridion.ContentDelivery.Webservice.LinkingService">
<endpoint behaviorConfiguration="webHttp" bindingConfiguration="HttpBinding" binding="webHttpBinding" contract="Tridion.ContentDelivery.Webservice.Ilinking" />
</service>
<service name="Tridi
I assume i'm attempting to consume the linking.svc in an incorrect way.
My question... Am I following the correct procedure for using the linking.svc service in a Visual Studio ASP.NET project? If not, please could you help me to understand how to utilise this api.
Many thanks

Did you consider writing your own client for the linking service? It is a quite simple REST-ful web service, so you can access it with a standard WebClient:
From an example by Mihai Cadariu:
WebClient client = new WebClient();
string linkingServiceUrl = "http://tridion.server:8080/services/linking.svc";
string COMPONENT_LINK = "/componentLink?sourcePageURI={0}&targetComponentURI={1}&excludeTemplateURI={2}&linkTagAttributes={3}&linkText={4}&showTextOnFail={5}&showAnchor={6}";
string url = linkingServiceUrl +
string.Format(COMPONENT_LINK,
sourcePageUri,
targetComponentUri,
excludeTemplateUri,
HttpUtility.UrlEncode(linkTagAttributes),
HttpUtility.UrlEncode(linkText),
showTextOnFail,
showAnchor);
return client.DownloadString(url);

Have you read the documentation here (requires login):
http://sdllivecontent.sdl.com/LiveContent/content/en-US/SDL_Tridion_2011_SPONE/reference_277A2D7264B04A39870C3FE18EF245BB

Related

Unable to add a service reference to SAP in web API

I am using a SAP service to get the data into the web API and then use that web API for the sharepoint client. The thing is when I consumed the SAP service in console application I got the data but when I used the web API it is showing following error
'Could not find default endpoint element that references contract 'AddonWCFService.SAPService' 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.'.
But in web.config I have the end point tag defined. My web.config has following code
<service name="RCWindsSvc.Service1" behaviorConfiguration="RCWindsSvc.Service1Behavior">
<endpoint address="http://....../SAPService.aspx"
binding="webHttpBinding"
contract="RCWindsSvc.IService1"
behaviorConfiguration="ServiceAspNetAjaxBehavior"
name="RCWindsSvcEndpoint"/>
<!-- behaviorConfiguration="WebBehaviour" /> -->
</service>

How to force soap header authentication for my scenario?

The problem is: I need to connect to a soap web service; generated by java code; using ASP.Net client via C# through MS Visual Studio 2013.
Try 1, The usual way:
I have added a web service reference using the wsdl and by assigning the credentials like:
Credentials.Username.Username = "test";
Credentials.Password.Password = "test";
When executing, the following exception is being encountered:
The login information is missing!
Try 2:
I have searched for similar problems like:
how-to-go-from-wsdl-soap-request-envelope-in-c-sharp
Dynamic-Proxy-Creation-Using-C-Emit
c# - Client to send SOAP request and received response
I had chosen to generate a proxy class using the wsdl tool, then added the
header attribute, but I have found the following note from Microsoft:
Note: If the Web service defines the member variables representing the SOAP headers of type SoapHeader or SoapUnknownHeader instead of a class deriving from SoapHeader, a proxy class will not have any information about that SOAP header.
Try 3:
I have tried to change the service model in the client web.config:
<bindings>
<basicHttpBinding>
<binding name="CallingCardServicePortBinding">
<security mode="TransportWithMessageCredential" >
<message clientCredentialType="UserName"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
Then added the credentials like the first try, but the following error appears:
MustUnderstand headers:[{http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd}Security] are not understood
So, now I don't know what to do !
I have no control over the web service and I need to build a client that understands it.
Help Please!
The Soap Request template is the following:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="...">
<soapenv:Header>
<credentials>
<userName>someUserName</userName>
<password>somePassword</password>
</credentials>
</soapenv:Header>
<soapenv:Body>
<ser:someRequest>
.......
.......
.......
</ser:someRequest>
If the destination web service uses authentication, then just ASMX won't do, since it is not aware of authentication, encryption etc. You have 2 options:
Use Microsoft WSE: http://www.microsoft.com/en-us/download/details.aspx?id=14089
this is nothing but an extension of ASMX which makes it Security/Encryption aware. (and some other features) technically, you'll be adding a reference to the WSE DLL and your Soap Proxy will extend from the WSE SOAP Client instead of the System one.
once you do that, the proxy class will have additional username/password properties that you can use to authenticate properly.
set the properties and see the outgoing request using fiddler. if the header is not what you want (because of namespaces etc.), then you can write a custom outgoing message inspector and modify the soap request nicely.
The other option (preferred) is to use WCF.
ASMX and WSE are older than WCF. WCF tries to bring all the web service nuances under one roof. if you get a WCF service reference, it (svcutil.exe) will automatically create the proxy class and the right bindings for you. (mostly custom)
once you do that, try setting the user name and password.
if that doesn't work, (i have frequently struggled to generate the right soap header for remote java based services that require username/password authentication), you can define a static header chunk in the web.config/app.config, that'll be sent as part of every request.
e.g.
<client>
<endpoint>
<headers>
<credentials>
<userName>someUserName</userName>
<password>somePassword</password>
</credentials>
</headers>
</endpoint>
</client>

WCF service timing out only when called from an ASP.NET web app

I have a few WPF applications that have WCF services with a single function called UpdateValues. I have about 5 applications working, but for some reason one is not. I tested the app using the WCF test application, and it is working correctly, so I believe the error is in the client.
The client is an ASP.NET 2.0 web application. The WCF service is added to the project as a web reference. When executed, the connection times out. The WCF function just contains a single line of code to make a beep, so I know the issue is not a real timeout due to processing time. If the WPF application is not running, the function call fails immediately.
I tried converting the app to .NET 4 and I get the same error.Any thoughts for getting a more detailed error message?
I found the issue, for some reason my app.config had changed the binding type to wsHttpBinding instead of basicHttpBinding. Everything is running fine now.
<endpoint address="" binding="basicHttpBinding" contract="JobSheetDisplay.IUpdateService">
<endpoint address="" binding="wsHttpBinding" contract="InkSetupDashboard.IUpdateService">

Calling webservice from windows service

I have a windows service project that references an asp.net webservice. When I run this service locally on my machine via VS it works fine and when I call the web method I get the results I want.
Today I deployed this to a test server and when I call the web method it fails because the it is trying to connect to the local host webservice and not the one on the server. The error I get is "Unable to Connect to remote server --> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it: 127.0.0.1"
My service has a app.config file and the web service settings are correctly pointing at the webservice url. I know the url is correct as when I put it into IE it resolves to the webservice. Also the properties of the webservices are correct.
Any suggestions on how the service is getting hold of localhost would be greatly appreciated.
Could be a windows security issue. Are you calling the process/web method as an elevated? Also, is Windows Firewall Service Running? If so is there an exception for the IP/port/app process? Is RPC running? Check credentials and those listed above.
I would recommend that you store your proxy's address using the standard WCF configuration. Here's an example.
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IService1" />
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://yourServerIP:51717/Service1.svc" binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_IService1" contract="ServiceReference1.IService1"
name="WSHttpBinding_IService1">
</endpoint>
</client>
</system.serviceModel>
Resolved this today at work with the following lines of code.
webservice ws = new webservice()
ws.Url = (new xxxx.Properties.Settings()).WS;
ws.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
Thanks for all your help guys
Cheers
APW

Problems with readerQuotas in ASP.NET application

I have an ASP.NET 4.0 Application.
A webservice is hosted using a .svc file linking a source (service implementation).
The web service .svc file is located inside a directory WebServs in the application root directory: MyApp/WebServs/mysvc.svc.
The web service is set using the Web.config (in the root directory).
<!-- Service model -->
<system.serviceModel>
<services>
<service name="DataAccessService">
<endpoint address=""
binding="basicHttpBinding"
bindingConfiguration="basicHttpBinding_ISRV"
contract="MyNamespace.ISRV">
</endpoint>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="basicHttpBinding_ISRV" maxReceivedMessageSize="2147483647">
<readerQuotas maxStringContentLength="1310720"
maxArrayLength="16384"
maxBytesPerRead="24096"
maxDepth="10000"
maxNameTableCharCount="16384"/>
</binding>
</basicHttpBinding>
</bindings>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
OK!
When I call the web service, I create the channel using a routine in order to encapsulate this commonly used logic:
public static ISRV GetService() {
try {
// Create the service endpoint
BasicHttpBinding bhttpb = new BasicHttpBinding(
BasicHttpSecurityMode.TransportCredentialOnly);
bhttpb.MaxReceivedMessageSize = 2147483647;
bhttpb.ReaderQuotas = new System.Xml.XmlDictionaryReaderQuotas();
bhttpb.ReaderQuotas.MaxArrayLength = 16384);
bhttpb.ReaderQuotas.MaxBytesPerRead = 24096);
bhttpb.ReaderQuotas.MaxDepth = 10000);
bhttpb.ReaderQuotas.MaxNameTableCharCount = 16384);
bhttpb.ReaderQuotas.MaxStringContentLength = 1310720);
ServiceEndpoint httpEndpoint =
new ServiceEndpoint(
ContractDescription.GetContract(typeof(ISRV)),
bhttpb,
new EndpointAddress());
// Create channel factory and get proper channel for service.
ChannelFactory<ISRV> channelFactory = new ChannelFactory<ISRV>(httpEndpoint);
IDAS svc = channelFactory.CreateChannel();
return svc;
} catch (Exception e) {
throw new DASException("DAS Exception: " + e.Message);
}
}
This routine is called by clients. Whilke the Web.config is used to configure the service server side.
When I try to execute my service with large messages (with tiny messages all's right) I get:
The formatter threw an exception while trying to deserialize the
message: There was an error while trying to deserialize parameter
http://((Namespace)):((Operation)). The InnerException message
was 'There was an error deserializing the object of type
((Type)),
App_Code.s5qoir2n, Version=0.0.0.0, Culture=neutral,
PublicKeyToken=null]]. The maximum string content length quota (8192)
has been exceeded while reading XML data. This quota may be increased
by changing the MaxStringContentLength property on the
XmlDictionaryReaderQuotas object used when creating the XML reader.
Line 31, position 1309.'. Please see InnerException for more details.
Don't understand. Both service and client have common settings, and this reads defaut values????? Furthermore I did as many other users did following instructions here in StackOverflow.
Please help me. Thankyou
You specified WCF 4.0 (well, ASP.NET 4.0 to be exact), so I wonder if the problem you're encountering is that you're actually hitting a default endpoint, which would use the default values for the binding unless otherwise overridden?
WCF 4.0 will supply a default endpoint (set to where the service is located at). That default endpoint will most likely use the default values for the binding (8192 in the case of the MaxStringContentLength).
Since you do all the configuration for the service in the directory above the WebServs directory (the root), perhaps it's resorting to a default endpoint? I do realize that the Web.config files will inherit from the ones above, but this is something to at least consider, if you haven't already.
More info on default endpoints and other changes for 4.0 can be found here: A Developer's Introduction to Windows Communication Foundation 4

Resources