Click here to Skip to main content
15,888,000 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to pass a base address with query input parameters for a WCF Service using web socket in ASP.NET with C#.

I created the base address Url dynamically.
By removing the query input parameters it is fine. But how could I pass these query parameters as base address based on which to generate the endpoint address

Getting the exception as below:
A base address cannot contain a Uri query string.
Parameter name: item

Below is the  base address I need to send as request 
<pre>https://10.15.15.15/CBWSO/wso?entityDetails={   
                  
                    

                     {                                     
                     "requestData": "2834367eec9be180739b628ae73e89ceac49ad575a3d00876105fe0321b3fc4a" ,
                     "requestkData": "2834367eec9be180739b628ae73e89ceac49ad575a3d00876105fe0321b3fc4a" 
                    }
                    
                  
                & entityId=123}


Response expected:
wss://10.15.15.15/CBWSO/wso?entityDetails={   
                  
                    

                     {                                     
                     "requestData": "2834367eec9be180739b628ae73e89ceac49ad575a3d00876105fe0321b3fc4a" ,
                     "requestkData": "2834367eec9be180739b628ae73e89ceac49ad575a3d00876105fe0321b3fc4a" 
                    }
                    
                  
                & entityId=123}


What I have tried:

Core code is as below:
string strHandShakeRequest = string.Empty;
    try
    {
        Logger.Log("Fetching of Encryption With AES for handshake Starts", LogFilename.WebPageLog, 3, MethodInfo.GetCurrentMethod().Name);

        string HandShakeParentUrl = hsk.HandShakeReqParentUrl;

        string RequestKeyData = hsk.requestKData;

        string RequestData = hsk.requestKData;

        string EntityID = hsk.EntityId;

        string json = @"



             {
             ""requestData"": """ + RequestKeyData + @""" ,
             ""requestkData"": """ + RequestData + @"""
            }


        ";




        StringBuilder strRequest = new StringBuilder();
        strRequest
       .Append(HandShakeReqParentUrl)
       .Append("=")
       .Append("{ ")
       .Append(json)
        .Append("& ")
       .Append("entityId=")
       .Append("")
       .Append(EntityId)
       . Append("")
       .Append("}");

        strHandShakeRequest = strRequest.ToString();



        Logger.Log("Fetching of Encryption With AES for handshake Ends", LogFilename.WebPageLog, 3, MethodInfo.GetCurrentMethod().Name);
    }
    catch (Exception ex)
    {
        throw ex;
    }
    return strHandShakeRequest;


Uri baseAddress = new Uri(strHandShakeRequest);
                       ServiceHost host = new ServiceHost(typeof(WebSocket_Stub.Service1), baseAddress);
Posted
Updated 19-Jun-18 0:43am
v3
Comments
F-ES Sitecore 19-Jun-18 6:56am    
You can't put a querystring on the base address, as it says in the error message. The base address the address to use as a starting point should you want to use a relative address for your service endpoints rather than an absolute one, it is also the link to the service that the requests connect to when requests are made. Have a look at the link below for more explanation and examples

https://docs.microsoft.com/en-us/dotnet/framework/wcf/specifying-an-endpoint-address

How you "solve" this issue depends on what this param data, who needs it etc. It could be you move it to the service, it could be you create an initialise method in your service where you pass this data, it could be you simply move the code that gets all of these keys into the service itself so they don't have to be passed in. We don't know what your ultimate aim is so it's hard to give specific advice. But please don't just re-iterate your question or create yet another thread on this topic. What you're trying to do isn't possible, you need an alternative solution.
ranio 19-Jun-18 10:21am    
What i meant whether it is possible to pass the web socket url with query string. I am doing it in in framework 4.6

Tried below way:

using (var ws = new WebSocket("ws://dragonsnest.far/Laputa"))
{
ws.connect();
}
such code line not supporting either. i am having a wcf service and want to set communication over the web socket in c#.
any solution there to do the same. without query string no issue.
ranio 19-Jun-18 10:41am    
I need to make a handshake request using web socket in asp.net. But how could i send the
same:
How could I make the HANDSHAKE request to the following URI:
(“wss://10.1.1.1/CBWSO/wso ?test=1&ade=2
Member 13296047 29-Apr-19 10:41am    
hello ranio, i am also trying to create handshake for ws however getting following error "A connection attempt failed because the connected party did not properly respond after a period of time or established connection failed because connected host has failed to respond 10.1.1.1:443"

I would appreciate your help if you could clarify my doubt regarding websocket handshake connection.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900