Login to jira soap api

坚强是说给别人听的谎言 提交于 2019-12-19 03:26:06

问题


I try use jira soap api on c#:

  1. create new project in VS2010
  2. add web service reference (JiraTest): http://jira.atlassian.com/rpc/soap/jirasoapservice-v2?wsdl
  3. write next code:

    static void Main(string[] args)
    {
        var jiraLogin = "soaptester";
        var jiraPassword = "soaptester";
        var jiraClient = new JiraTest.JiraSoapServiceClient();
        var projects = jiraClient.getProjects();
    }
    

But this code throw exepition that I'm not autentificate yet. I try find login method, but it have next signature:

public void login();

Where are no loginname and password parameters. When I use this login method code throw exeption that login or password invalid. And I don't known where I must set my credentials.

How I can login with jira soap api before call needed method?

Added: see https://developer.atlassian.com/display/JIRADEV/Creating+a+JIRA+SOAP+Client


回答1:


You can try this

    JiraSoapServiceService jiraSoapService = new JiraSoapServiceService();

    public string Login(string user, string pwd)
    {
        string result = string.Empty;

        result = jiraSoapService.login(user, pwd);

        return result;

    }


    public void Logout(string token)
    {
        jiraSoapService.logout(token);
    }



回答2:


I had the same problem and found the answer. You need to add it as a Web Reference. It will bring in the parameters but as they appear in the WSDL so login(string username, string password) become login(string in0, string in1) but atleast it's usable.

So steps:

  • Right-click Project and click "Add Service References..." (just like before)
  • Click "Advanced..." in the bottom left of the dialog
  • Click "Add Web Reference..." in the bottom left of the dialog
  • Enter the WSDL Url in the Url Box for example "https://jira.atlassian.com/rpc/soap/jirasoapservice-v2?WSDL"
  • Click the green go arrow
  • Name your reference in the Web reference name: box
  • Click "Add Reference"



回答3:


I found myself in the same situation but could not go with the 'Web Service Service' solution as I needed to control the binding configuration (sendTimeout, maxReceivedMessageSize etc).

You can solve this by manually generating the JIRA WCF proxy via svcutil.exe. For instance:

 1. Run svcutil.exe http://myhostname/rpc/soap/jirasoapservice-v2?wsdl /n:*,mynamespace
 2. Copy output source file to your project
 3. Copy configuration (output.config) to your app.config.


来源:https://stackoverflow.com/questions/8787121/login-to-jira-soap-api

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!